public static string Decode(string morseCode) { string[] morseWords = morseCode.Split(" "); string translatedMorseCode = ""; // foreach (string s in morseWords) // { // Console.WriteLine(s); // } foreach (string word in morseWords) { string[] letters = word.Split(" "); foreach (string letter in letters) { translatedMorseCode += MorseCode.Get(letter); } translatedMorseCode += " "; } translatedMorseCode = translatedMorseCode.Trim(' '); return(translatedMorseCode); throw new System.NotImplementedException("Please provide some code."); }
public static string Decode(string morseCode) { Regex regex = new Regex("[ ]{3,}", RegexOptions.None); morseCode = regex.Replace(morseCode.Trim(), " "); return(String.Join("", morseCode.Split(' ').Select(x => x == "" ? " " : MorseCode.Get(x)))); }
public static string Decode(string morseCode) { morseCode = morseCode.Replace(" ", " "); string[] morseCodeArr = morseCode.Split(" "); string result = ""; foreach (string x in morseCodeArr) { if (x == "") { result += " "; } else { result += MorseCode.Get(x); } } while (result[0] == ' ') { result = result.Substring(1); } while (result[result.Length - 1] == ' ') { result = result.Substring(0, result.Length - 1); } return(result); }
public static string Decode(string morseCode) { string Decoded = ""; morseCode = morseCode.Trim(); morseCode = morseCode.Replace(" ", " # "); foreach (var character in morseCode.Split(' ')) { if (character == "#") { Decoded = Decoded + ' '; } else { Decoded = Decoded + MorseCode.Get(character); } } return(Decoded); throw new System.NotImplementedException("Please provide some code."); }
public static string GetLetter(string w) { int index = w.IndexOf(" ") - 1; string encodedWord = w.Substring(0, index); return(MorseCode.Get(encodedWord)); }
public static string Decode(string morseCode) { string letter = ""; string result = ""; morseCode = morseCode.Trim(); for (int i = 0; i < morseCode.Length; i++) { if (!morseCode[i].Equals(' ')) { letter += morseCode[i]; } else { result += MorseCode.Get(letter); letter = ""; if (morseCode[i - 1].Equals(' ') && morseCode[i + 1].Equals(' ')) { result += " "; } } if (i == morseCode.Length - 1) { result += MorseCode.Get(letter); } } return(result); }
public static string DecodeMorse(string morseCode) { var decode = new StringBuilder(); var code = new StringBuilder(); int spaceCount = 0; bool openParentheses = false; foreach (char c in morseCode) { switch (c) { case '.': case '-': if (spaceCount == 3) { decode.Append(' '); } code.Append(c); spaceCount = 0; break; case ' ': if (spaceCount == 0) { if (code.Length > 0) { string key = code.ToString(); if (key == "-.--.-") { decode.Append(openParentheses ? ')' : '('); openParentheses = !openParentheses; } else { decode.Append(MorseCode.Get(key)); } code.Length = 0; spaceCount = 1; } } else { spaceCount++; } break; default: throw new ArgumentException(nameof(morseCode)); } } if (code.Length > 0) { decode.Append(MorseCode.Get(code.ToString())); } return(decode.ToString()); }
public static string Decode(string morseCode) { string[] morseWords = morseCode.Split(' '); for (int i = 0; i < morseWords.Length; i++) { morseWords[i] = morseWords[i].Length == 0? "¬" : MorseCode.Get(morseWords[i]); } return(string.Join("", morseWords).Replace("¬¬", " ").Replace("¬", "").Trim()); }
public static string Decode(string morseCode) { var decodedCode = morseCode .Trim() .Replace(" ", " W ") .Split(' ') .Select(w => w == "W" ? " " : MorseCode.Get(w)); return(string.Join("", decodedCode)); }
public static string DecodeLetters(string[] letters) { var sb = new StringBuilder(); foreach (var s in letters) { sb.Append(MorseCode.Get(s)); } return(sb.ToString()); }
public static string Decode(string morseCode) { var code = morseCode.Trim().Replace(" ", " | ").Split(' '); string message = ""; foreach (var codeLetter in code) { message += codeLetter == "|" ? " " : MorseCode.Get(codeLetter); } return(message); }
public static string Decode(string morseCode) { string message = ""; foreach (string word in Regex.Split(morseCode, " ")) // If there are 3 spaces between chars, it's a new word { foreach (string letter in word.Split(' ')) { message += MorseCode.Get(letter); // Decoding single letter in word and adding it to message } message += " "; // Adding space between words in message } return(message.Trim()); }
public static string DecodeMorse(string morseCode) { var words = morseCode.Split(" ", StringSplitOptions.RemoveEmptyEntries); var text = ""; foreach (var word in words) { var letters = word.Split(" ", StringSplitOptions.RemoveEmptyEntries); text = letters.Aggregate(text, (current, letter) => current + MorseCode.Get(letter)); text += " "; } text = text.Trim(); return(text); }
public static string Decode(string morseCode) { string[] arr = morseCode.Split(' '); for (int i = 0; i < arr.Length; i++) { string y = MorseCode.Get(arr[i]); arr[i] = y; } string ans = string.Join(" ", arr); ans = ans.Replace(" ", "~"); ans = ans.Replace(" ", ""); ans = ans.Replace("~", " "); ans = ans.Trim(); return(ans); }
//Decodes morse code string public static string DecodeMorse(string morseCode) { string[] words = Regex.Split(morseCode, " "); string result = ""; foreach (string w in words) { string[] chars = w.Split(' '); foreach (string c in chars) { result += MorseCode.Get(c); } result += " "; } return(result.Trim()); }
public static string Decode(string morseCode) { var decodedMessage = new StringBuilder(); var strippedMessage = morseCode.Trim(); var words = strippedMessage.Split(" "); foreach (var word in words) { var chars = word.Split(" "); foreach (var c in chars) { decodedMessage.Append(MorseCode.Get(c)); } decodedMessage.Append(" "); } return(decodedMessage.ToString().Trim()); }
public static string DecodeMorse(string morseCode) { string output = ""; string[] words = morseCode.Split(" "); for (int i = 0; i < words.Length; i++) { string[] characters = words[i].Split(" "); foreach (string c in characters) { output += MorseCode.Get(c); } if (i != words.Length - 1) { output += " "; } } return(output); }
public static string Decode(string morseCode) { var letterArray = morseCode.Split(' '); var decodedMessage = ""; foreach (var letter in letterArray) { if (letter == "" && !decodedMessage.EndsWith(" ")) { decodedMessage += " "; } else { decodedMessage += MorseCode.Get(letter); } } return(decodedMessage.Trim()); }
public static string Decode(string morseCode) { var wordsInMorse = morseCode.Trim().Split(" "); var wordsDecoded = new List <string>(); foreach (var word in wordsInMorse) { var charsInMorse = word.Split(); var charsDecoded = new List <string>(); foreach (var s in charsInMorse) { charsDecoded.Add(MorseCode.Get(s)); } wordsDecoded.Add(string.Concat(charsDecoded)); } return(string.Join(" ", wordsDecoded)); }
public static string DecodeMorse(string morseCode) { morseCode = morseCode.Replace(" ", " w "); string [] words = morseCode.Split(" "); string result = ""; foreach (var word in words) { if (word == "w") { result = result + " "; } else { result = result + MorseCode.Get(word); } } return(result); }
public static string Decode(string morseCode) { //Call MorseCode.Get('.--') to convert to letter. string result = ""; string message = morseCode; int spacePos = 0; //Step through all characters finding words and spaces while (message.Length > 0) { spacePos = message.IndexOf(" "); if (spacePos == -1) //no spaces let, just get last letter { result += MorseCode.Get(message); break; } if (message.StartsWith(" ")) //We have a space between words { result += " "; //no need to decode space message = message.Substring(2); continue; } result += MorseCode.Get(message.Substring(0, spacePos - 1)); //ignore space message = message.Substring(spacePos + 1); //skip space we found } return(result); /* * //result += GetLetter(morseCode); * * int start = 0; * int count; * int end = morseCode.Length; * int at = 0; * int space; * * int index = 0; * bool hasLetters = true; * * while ((start <= end) && (at > -1)) * { * // start+count must be a position within -str-. * count = end - start; //10 - 0; * * * at = morseCode.IndexOf(" ", start, count); // 4 * * if (at == -1) break; //single space not found * * space = 0; * if (start+2 > end) * { * //more here * space = morseCode.IndexOf(" ", start, start + 2); // 4 * } * * * if (space == -1) //no space * { * result += MorseCode.Get(morseCode.Substring(start, at - start)); * start = at + 1; * * } * else * { * * result += " "; * start = at + 3; * } * * * } */ //return result; }