此代碼屬改造而來
輸出示例
引發 System
Yin
Hello!重慶和深圳的特色各是什麼呢?
Hello!Chong Qing He Shen Zhen De Te Se Ge Shi ShenMe Ne ?
代碼如下
/**//// <summary>
/// 漢字轉拼音工具
/// </summary>
public sealed class CHS
/**//// <summary>
/// 包含字符 ASC 碼的整形數組
/// </summary>
private static int[] pv = new int[]
/**//// <summary>
/// 包含漢字拼音的字符串數組
/// </summary>
private static string[] ps = new string[]
/**//// <summary>
/// 包含要排除處理的字符的字符串數組
/// </summary>
private static string[] bd = new string[]
private static Hashtable _Phrase;
/**//// <summary>
/// 設置或獲取包含列外詞組讀音的鍵/值對的組合
/// </summary>
public static Hashtable Phrase
get
if (_Phrase == null)
_Phrase = new Hashtable();
_Phrase
_Phrase
_Phrase
}
return _Phrase;
}
set
}
/**//// <summary>
/// 將指定中文字符串轉換為拼音形式
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <returns>包含中文字符串的拼音的字符串
public static string Convert(string chs
if (chs == null || chs
if (separator == null || separator
// 例外詞組
foreach (DictionaryEntry de in CHS
chs = chs
}
byte[] array = new byte[
string returnstr =
int chrasc =
int i
int i
bool b = false;
char[] nowchar = chs
CultureInfo ci = Thread
TextInfo ti = ci
for (int j =
array = Encoding
string s = nowchar[j]
if (array
b = true;
returnstr += s;
}
else
if (s ==
if (returnstr ==
else returnstr += separator + s;
continue;
}
i
i
chrasc = i
for (int i = (pv
if (pv <= chrasc)
s = ps;
if (initialCap == true) s = ti
if (returnstr ==
else returnstr += separator + s;
break;
}
}
b = false;
}
}
returnstr = returnstr
return returnstr;
}
/**//// <summary>
/// 將指定中文字符串轉換為拼音形式
/// </summary>
/// <param name=
/// <param name=
/// <returns>包含中文字符串的拼音的字符串
public static string Convert(string chs
return CHS
}
/**//// <summary>
/// 將指定中文字符串轉換為拼音形式
/// </summary>
/// <param name=
/// <param name=
/// <returns>包含中文字符串的拼音的字符串
public static string Convert(string chs
return CHS
}
/**//// <summary>
/// 將指定中文字符串轉換為拼音形式
/// </summary>
/// <param name=
/// <returns>包含中文字符串的拼音的字符串
public static string Convert(string chs)
return CHS
}
}
From:http://tw.wingwit.com/Article/program/net/201311/13608.html