Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 有没有库可以将数字拼音转换成带声调标记的拼音?_C#_.net_Unicode_Cjk - Fatal编程技术网

C# 有没有库可以将数字拼音转换成带声调标记的拼音?

C# 有没有库可以将数字拼音转换成带声调标记的拼音?,c#,.net,unicode,cjk,C#,.net,Unicode,Cjk,我只是想知道是否有人知道有一个类库可以将汉语拼音转换成带声调的拼音,比如nin2 hao3 ma到nín hǎo ma。它将类似于,但希望使用.NET framework。我使用了Microsoft Visual Studio International Pack 这是和 希望能帮助你 这是我将@Greg Hewgill移植到C#的过程。到目前为止,我还没有遇到任何问题 public static string ConvertNumericalPinYinToAccented(string in

我只是想知道是否有人知道有一个类库可以将汉语拼音转换成带声调的拼音,比如nin2 hao3 ma到nín hǎo ma。它将类似于,但希望使用.NET framework。

我使用了Microsoft Visual Studio International Pack

这是和


希望能帮助你

这是我将@Greg Hewgill移植到C#的过程。到目前为止,我还没有遇到任何问题

public static string ConvertNumericalPinYinToAccented(string input)
    {
        Dictionary<int, string> PinyinToneMark = new Dictionary<int, string>
        {
            {0, "aoeiuv\u00fc"},
            {1, "\u0101\u014d\u0113\u012b\u016b\u01d6\u01d6"},
            {2, "\u00e1\u00f3\u00e9\u00ed\u00fa\u01d8\u01d8"},
            {3, "\u01ce\u01d2\u011b\u01d0\u01d4\u01da\u01da"},
            {4, "\u00e0\u00f2\u00e8\u00ec\u00f9\u01dc\u01dc"}
        };

        string[] words = input.Split(' ');
        string accented = "";
        string t = "";
        foreach (string pinyin in words)
        {
            foreach (char c in pinyin)
            {
                if (c >= 'a' && c <= 'z')
                {
                    t += c;
                }
                else if (c == ':')
                {
                    if (t[t.Length - 1] == 'u')
                    {
                        t = t.Substring(0, t.Length - 2) + "\u00fc";
                    }
                }
                else
                {
                    if (c >= '0' && c <= '5')
                    {
                        int tone = (int)Char.GetNumericValue(c) % 5;

                        if (tone != 0)
                        {
                            Match match = Regex.Match(t, "[aoeiuv\u00fc]+");
                            if (!match.Success)
                            {
                                t += c;
                            }
                            else if (match.Groups[0].Length == 1)
                            {
                                t = t.Substring(0, match.Groups[0].Index) +
                                    PinyinToneMark[tone][PinyinToneMark[0].IndexOf(match.Groups[0].Value[0])]
                                    + t.Substring(match.Groups[0].Index + match.Groups[0].Length);
                            }
                            else
                            {
                                if (t.Contains("a"))
                                {
                                    t = t.Replace("a", PinyinToneMark[tone][0].ToString());
                                }
                                else if (t.Contains("o"))
                                {
                                    t = t.Replace("o", PinyinToneMark[tone][1].ToString());
                                }
                                else if (t.Contains("e"))
                                {
                                    t = t.Replace("e", PinyinToneMark[tone][2].ToString());
                                }
                                else if (t.Contains("ui"))
                                {
                                    t = t.Replace("i", PinyinToneMark[tone][3].ToString());
                                }
                                else if (t.Contains("iu"))
                                {
                                    t = t.Replace("u", PinyinToneMark[tone][4].ToString());
                                }
                                else
                                {
                                    t += "!";
                                }
                            }
                        }
                    }
                    accented += t;
                    t = "";
                }
            }
            accented += t + " ";
        }
        accented = accented.TrimEnd();
        return accented;
    }
公共静态字符串ConvertNumericalPinyinToAccent(字符串输入)
{
字典拼音标记=新字典
{
{0,“aoeiuv\u00fc”},
{1,“\u0101\u014d\u0113\u012b\u016b\u01d6\u01d6”},
{2,“\u00e1\u00f3\u00e9\u00ed\u00fa\u01d8\u01d8”},
{3,“\u01ce\u01d2\u011b\u01d0\u01d4\u01da\u01da”},
{4,“\u00e0\u00f2\u00e8\u00ec\u00f9\u01dc\u01dc”}
};
string[]words=input.Split(“”);
字符串重音=”;
字符串t=“”;
foreach(字串拼音)
{
foreach(拼音字符c)
{
如果(c>='a'&&c='0'&&c我认为这一行

t = t.Substring(0, t.Length - 2) + "\u00fc";
应该是这个吗

t = t.Substring(0, t.Length - 1) + "\u00fc";

@贾斯汀:你介意举个例子吗?我发现的帮助文件(或任何少数代码示例)中都没有提到数字拼音和音调拼音之间的转换,我想这是对