1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-19 22:16:57 +02:00
CodeWars/6kyu/word_a10n/solution.cs

33 lines
647 B
C#
Raw Normal View History

using System;
public class Abbreviator
{
public static string Abbreviate(string input)
{
string result = "", temp = "";
for (int i = 0; i < input.Length; i++)
{
if (Char.IsLetter(input[i]))
temp += input[i];
else
{
if (temp.Length <= 3) result += temp + input[i];
else
{
result += temp[0] + (temp.Length - 2).ToString() + temp[temp.Length - 1] + input[i];
}
temp = "";
}
}
if (temp.Length <= 3) result += temp;
else
{
result += temp[0] + (temp.Length - 2).ToString() + temp[temp.Length - 1];
}
return result;
}
}