Beispiel #1
0
        public static string Decode(string morseCode)
        {
            morseCode = morseCode.Trim().Replace("  ", " _");
            var splitted = morseCode.Split(" ");
            var decoded  = string.Empty;

            foreach (var letter in splitted)
            {
                if (letter == "_")
                {
                    decoded += " ";
                }
                else
                {
                    decoded += MorseCode.Get(letter);
                }
            }
            return(decoded);
        }
Beispiel #2
0
        public string Decode(string morseCode)
        {
            var result = new StringBuilder();

            var words = morseCode.Split("   ");

            foreach (var word in words)
            {
                var characters = word.Split(' ');

                foreach (var character in characters)
                {
                    var convertedCharacter = MorseCode.Get(character);
                    result.Append(convertedCharacter);
                }

                result.Append(" ");
            }

            return(result.ToString().Trim());
        }
Beispiel #3
0
 public static string DecodeMorse(string morseCode)
 {
     return(string.Concat(string.Concat(morseCode.Split().Select(x => x = x == string.Empty ? " " : MorseCode.Get(x))).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select((x, i) => x += " ")).TrimEnd(' '));
 }