1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-08 18:49:07 +01:00
CodeWars/6kyu/word_a10n/solution.cs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

32 lines
647 B
C#

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;
}
}