public static bool IsJapaneseMorseCode(string str) { return(str .Replace(" ", " ") .Split(' ') .All(_ => JapaneseMorseCodeList.Exists(__ => __.Item2 == _))); }
public static string ToJapaneseMorseCode(string str) { return(string.Join(" ", str .ToCharArray() .Select(_ => { if (JapaneseMorseCodeList.Exists(__ => string.Compare(__.Item1.ToString(), _.ToString(), CultureInfo.CurrentCulture, CompareOptions.IgnoreKanaType) == 0)) { return JapaneseMorseCodeList.First(__ => string.Compare(__.Item1.ToString(), _.ToString(), CultureInfo.CurrentCulture, CompareOptions.IgnoreKanaType) == 0).Item2; } else { return _.ToString(); } }))); }
public static string ParseJapaneseMorseCode(string str) { return(str .Split(' ') .Select(_ => { if (JapaneseMorseCodeList.Exists(__ => __.Item2 == _)) { return JapaneseMorseCodeList.First(__ => __.Item2 == _).Item1.ToString(); } else { return _; } }) .Aggregate(new StringBuilder(), (sb, _) => sb.Append(_)) .ToString()); }