将字符串中的字母更改为短语(例如,将D更改为Delta,)

时间:2019-06-18 16:45:16

标签: c# visual-studio-2012

我目前正在编写一个小型ATC程序。我正在使用文本转语音功能,并且希望它像航空字母一样读取字母。例如,A被称为Alpha,B被称为Bravo,等等。

此刻,我使用了显示的查找和替换方法,但是我觉得这是低效的并且不必要的。

lblDialogHidden.Text = txtCallsign.Text.Replace("D", "Delta, ");
lblDialogHidden.Text = txtCallsign.Text.Replace("E", "Echo, ");

// this converts the Letters to Aviation Alphabet phrases, so they are spoken rather than sounded out, or spoken as a complete word such as DEG.

这行得通,但是正如我说的那样,这似乎是最糟糕的方式来做我想做的事。

2 个答案:

答案 0 :(得分:1)

最好像这样一口气处理整个字符串:

DocumentId IN (  
SELECT  {%TopDocuments%}  DocumentId  FROM CMS_Document join CMS_DocumentCategory ON CMS_Document.DocumentID =  CMS_DocumentCategory.CategoryID
     WHERE CategoryId  IN {%CurrentDocument.Categories.IDs#%} and DocumentID <> {% CurrentDocument.DocumentId #%}
{%DocumentsOrderBy%}
)

填写缺少的语音代码,然后离开。

答案 1 :(得分:0)

在这种情况下,您可以使用Dictonary

public static void Main()
    {
            Dictionary<char, string> dDict = new Dictionary<char, string>() { { 'a', "Alfa" }, { 'b', "Bravo" } };
            string result = string.Join(" ", "abc".Select(x => dDict.Select(p=>p.Key).Contains(x) ? dDict[char.ToLower(x)] : x.ToString()));
            Console.WriteLine(result);
    }

输出:

Alfa Bravo c