C# 将摩尔斯电码解码为文本

C# 将摩尔斯电码解码为文本,c#,silverlight,windows-phone-7,C#,Silverlight,Windows Phone 7,当我试图将输入的莫尔斯电码替换成文本时,我遇到了一个问题。基本上,问题是当用户输入“.”时,prorgram打印字母“E”(摩尔斯电码中的“.”),并忽略其后的所有其他句点,以生成具有两个或更多连续句点的其他字母 我应该如何解决这个问题 我知道这可能是一个非常新的问题,但我一整天都在努力寻找答案 这是密码 public partial class Morsetext : PhoneApplicationPage { public string[] aakkoset = { ".", "

当我试图将输入的莫尔斯电码替换成文本时,我遇到了一个问题。基本上,问题是当用户输入“.”时,prorgram打印字母“E”(摩尔斯电码中的“.”),并忽略其后的所有其他句点,以生成具有两个或更多连续句点的其他字母

我应该如何解决这个问题

我知道这可能是一个非常新的问题,但我一整天都在努力寻找答案

这是密码

public partial class Morsetext : PhoneApplicationPage
{

    public string[] aakkoset = { ".", "A", "B", "C", "D", "E", 
                                 "F", "G", "H", "I", "J", 
                                 "K", "L", "M", "N", "O", 
                                 "P", "Q", "R", "S", "T", 
                                 "U", "V","W", "X", "Y", 
                                 "Z", "Ä", "Ö", "0", "1", 
                                 "2", "3", "4", "5", "6", 
                                 "7", "8", "9", "?", ":",
                                 ",", "@", "/", "=", " ",
                                 };
    public string[] morse = {".-.-.-", ".-", "-...", "-.-.", "-..", ".", 
                              "..-.", "--.", ".... ", "..", ".---", 
                              "-.-", ".-..", "--", "-.", "---", 
                              ".--.", "--.-", ".-.", "...", "-", 
                              "..-", "...-", ".--", "-..-", "-.--", 
                              "--..", ".-.-", "---.", "-----", ".----", 
                              "..---", "...--", "....-", ".....", "-....", 
                              "--...", "---..","----.", "..--..", "---...",
                              "-....-", ".--.-.", "-..-.", "-...-", " ", 
                              };

    public Morsetext()
    {
        InitializeComponent();
    }

    private void bShort_Click(object sender, RoutedEventArgs e)
    {
        char piste = '.';

        tBoxMorse2.Text += piste.ToString();

    }

    private void tBoxMorse2_TextChanged(object sender, TextChangedEventArgs e)
    {

        tBlockText2.Text =  tBoxMorse2.Text.ToUpper()
            .Replace(morse[0],aakkoset[0])
            .Replace(morse[1],aakkoset[1])
            .Replace(morse[2],aakkoset[2])
            .Replace(morse[3],aakkoset[3])
            .Replace(morse[4],aakkoset[4])
            .Replace(morse[5],aakkoset[5])
            .Replace(morse[6],aakkoset[6])
            .Replace(morse[7],aakkoset[7])
            .Replace(morse[8],aakkoset[8])
            .Replace(morse[9],aakkoset[9])
            .Replace(morse[10],aakkoset[10])
            .Replace(morse[11],aakkoset[11])
            .Replace(morse[12],aakkoset[12])
            .Replace(morse[13],aakkoset[13])
            .Replace(morse[14],aakkoset[14])
            .Replace(morse[15],aakkoset[15])
            .Replace(morse[16],aakkoset[16])
            .Replace(morse[17],aakkoset[17])
            .Replace(morse[18],aakkoset[18])
            .Replace(morse[19],aakkoset[19])
            .Replace(morse[20],aakkoset[20])
            .Replace(morse[21],aakkoset[21])
            .Replace(morse[22],aakkoset[22])
            .Replace(morse[23],aakkoset[23])
            .Replace(morse[24],aakkoset[24])
            .Replace(morse[25],aakkoset[25])
            .Replace(morse[26],aakkoset[26])
            .Replace(morse[27],aakkoset[27])
            .Replace(morse[28],aakkoset[28])
            .Replace(morse[29],aakkoset[29])
            .Replace(morse[30],aakkoset[30])
            .Replace(morse[31],aakkoset[31])
            .Replace(morse[32],aakkoset[32])
            .Replace(morse[33],aakkoset[33])
            .Replace(morse[34],aakkoset[34])
            .Replace(morse[35],aakkoset[35])
            .Replace(morse[36],aakkoset[36])
            .Replace(morse[37],aakkoset[37])
            .Replace(morse[38],aakkoset[38])
            .Replace(morse[39],aakkoset[39])
            .Replace(morse[40],aakkoset[40])
            .Replace(morse[41],aakkoset[41])
            .Replace(morse[42],aakkoset[42])
            .Replace(morse[43],aakkoset[43])
            .Replace(morse[44],aakkoset[44]);

    }

最简单的解决方案是将替换项从最长的莫尔斯字符串第一个重新排序到最短的莫尔斯字符串最后一个

莫尔斯电码可以用密码解码。决策树


那句“替换”的话让我眼冒金星。我为难看的语法道歉。我还在学这些东西。非常感谢你!我这样做了,现在它的工作像一个魅力!谢谢你,帕拉普拉·拉吉库马尔!我按照这个图表来解决这个问题。