漢字轉換成拼音

2021-05-22 16:02:28 字數 1400 閱讀 2221

c# 乙個有用的漢字轉拼音類

c#漢字轉換為拼音的類,含大小寫轉換 

因為是靜態函式 呼叫方法很簡單

crazycoderpinyin.convert("瘋狂**");

**如下:

using system;

using system.collections.generic;

using system.text;

using system.text.regularexpressions;

using system.web;

namespace crazycoder.common

;///

/// 定義陣列

///

private static string pyname = new string

;///

/// 漢字轉換

/// 把漢字轉換成拼音(全拼)

/// 漢字字串

/// 轉換後的拼音(全拼)字串

public static string convert(string hzstring,int maxlength)

", "").replace("^", "").replace("&", "_").replace("=", "").replace("~", "_").replace("@", "_").replace("¥", "");

if (hzstring.length > maxlength)

regex regex = new regex(@"([a-za-z0-9/._]+)", regexoptions.ignorecase);

if (regex.ismatch(hzstring))

}// 匹配中文字元

regex = new regex("^[/u4e00-/u9fa5]$");

byte array = new byte[2];

string pystring = "";

int chrasc = 0;

int i1 = 0;

int i2 = 0;

char nowchar = hzstring.tochararray();

for (int j = 0; j < nowchar.length; j++)

else}}

}}// 非中文本元

else

}return pystring;}}

}

Python漢字轉換成拼音

最近在使用python做專案時,需要將漢字轉化成對應的拼音.網上的一些包大多是python2.x的,使用下面這個包,支援python3.6 from xpinyin import pinyin p pinyin default splitter is p.get pinyin u 上海 shang ...

js 漢字轉換成拼音

npm install js pinyin main.js 引入 import pinyin from js pinyin 使用元件內 let pinyin require js pinyin pinyin.setoptions console.log pinyin.getfullchars 管理員...

Python 將拼音轉換成漢字

利用pinyin2hanzi 可以將拼音轉換為漢字,可以作為拼音輸入法的轉換引擎 示例 def pinyin 2 hanzi pinyinlist from pinyin2hanzi import defaultdagparams from pinyin2hanzi import dag dagpa...