aardio漢字轉拼音簡拼首字母

2022-09-06 00:54:09 字數 699 閱讀 4638

import console;

import string.conv;

import string.conv.pinyin;

var pinyin = string.conv.pinyin("拼音首字母123456789陶喆dasklfjalkjlksaf.-_=+-*");

var str = string.replace(pinyin,"(\w)\w+\s*","\1");

str = string.replace(str,"\s","");

console.log( string.conv.lower(str));

console.pause(true);

執行效果:

後來又遇到了問題,當輸入的文字是純數字或者純字母而沒有包含漢字的時候,string.conv.pinyin()函式的返回值是乙個table。

解決辦法:

可以先判斷string.conv.pinyin()函式的返回值,如果是table,直接取傳入的文本來作為該文字的簡拼返回。如果不是table則繼續用string.replace()去取文字的簡拼返回。

漢字轉拼音或轉拼音首字母

漢字轉拼音或轉拼音首字母 public class chinesetospell private static string pyname new string 把漢字轉換成拼音 全拼 漢字字串 轉換後的拼音 全拼 字串 public static string characterconvertst...

漢字轉拼音或轉拼音首字母

漢字轉拼音或轉拼音首字母 public class chinesetospell private static string pyname new string 把漢字轉換成拼音 全拼 漢字字串 轉換後的拼音 全拼 字串 public static string characterconvertst...

漢字轉拼音首字母

public string hz2py string hz 獲得漢字的區位碼 else if tmp 45253 tmp 45760 else if tmp 47761 tmp 46317 else if tmp 46318 tmp 46825 else if tmp 46826 tmp 47009...