中英混串轉拼音 原始碼

2021-07-04 08:23:48 字數 1028 閱讀 2312

/* 本程式只對gb2312編碼有效 */

/* 漢字讀音分界點處的碼值陣列 */

static const unsigned short code_pin = ;

/* 漢字讀音陣列 */

static const char *str_pin = ;

/* 陣列長度 */

static const size_t size_array = sizeof(code_pin) / sizeof(short);

#include #include using std::string;

using std::cout;

using std::endl;

/* 獲取乙個漢字的拼音 */

const char* get_pin(unsigned short char_zh)

return str_pin[char_zh >= code_pin[high] ? high : low];

}/* 將中英混合字串轉化成拼音形式 */

string str_to_pin(string const &input)

}return result;

}/* 將中英混合字串轉化成拼音形式,每個拼音後跟乙個空格 */

string str_to_pin_space(string const &input)

else

}return result;

}/*

將中英及數字混合串轉化成拼音,且每一連續部分之間放置乙個空格。

輸入必須滿足只有上述三種字元的情況,正確性需要由呼叫端保證。

*/string str_to_pin_space_(string const &input)

}else if (high_byte > 64 && high_byte < 123)// 英文本元

}else// 漢字字元

}return result;

}/* 測試** */

int main()

中文轉拼音 中英文首字母提取

import net.sourceforge.pinyin4j.pinyinhelper import net.sourceforge.pinyin4j.format.hanyupinyincasetype import net.sourceforge.pinyin4j.format.hanyupi...

iconv substr擷取php中英文混排字串

php5中解決中英文混排字串的函式包括iconv substr iconv strpos iconv strlen substr 函式可以分割文字,但要分割的文字如果包括中文字元往往會遇到問題,這時可以用mb substr mb strcut這個函式,mb substr mb strcut的用法與s...

漢字轉拼音

region 漢字轉拼音 漢字轉拼音類 用法 crazycoderpinyin.covent 漢字 長度 using system.text.regularexpressions build date 20030610 public class crazycoderpinyin 定義陣列 priva...