关于汉字转换全拼音的问题
在网上只查到了一个转换拼音简码的例子,代码如下,怎么能改成全拼音的代码呢?
PROCEDURE CHTOPY
LPARAMETERS cstring
LOCAL cpinyin,i,j,ctemp,cchr
cpinyin=""
SET COLLATE TO "PINYIN"
Pycode="八嚓咑妸发旮铪讥讥咔垃呣拿讴趴七呥仨他哇哇哇夕丫匝咗"
FOR i=1 TO LEN(cstring)
IF ASC(SUBSTR(cstring,i,1))>160 &&判断是否为汉字
Cchr=SUBSTR(cstring,i,2)
ctemp=""
FOR j=1 TO 26
IF SUBSTRC(cchr,1,1)<SUBSTRC(Pycode,j,1) &&进行汉字比较
ctemp=CHR(96+j) &&得到首位拼音码
EXIT
ENDIF
ENDFOR
cpinyin=cpinyin+UPPER(ctemp)
i=i+1
ELSE
cpinyin=cpinyin+UPPER(SUBSTR(cstring,i,1))
ENDIF
ENDFOR
RETURN cpinyin
[解决办法]
CLEAR
CST=[出差,差错,参差不齐]
?PY(CST,2)
FUNCTION PY
PARAMETERS CSTR,N
*---- 如果N=1 转换字符为简拼,N=2 转换字符为全拼; CSTR:要转换的汉字
LOCAL CPY,CHZ
STORE "" TO CPY,CHZ
FOR I=1 TO LENC(CSTR)
IF LEN(SUBSTRC(CSTR,I,1))=2
CHZ=SUBSTRC(CSTR,I,1)
SELECT 汉字,拼音 FROM WINPYK WHERE ALLTRIM(汉字)==CHZ INTO CURSOR TEMP
GO TOP
DO CASE
CASE RECCOUNT([TEMP])=0 && 未找到,取字符CHZ
CPY=CPY+CHZ
CASE RECCOUNT([TEMP])=1 && 无多音字,取首拼或拼音
CPY=CPY+IIF(N=1,UPPER(ALLTRIM(LEFT(拼音,1))),PROPER(ALLTRIM(拼音)))
CASE RECCOUNT([TEMP])>1 && 有多音字,选择首拼或拼音
BROWSE && 如果在表单中,此处可用控件做一选择提示
CPY=CPY+IIF(N=1,UPPER(ALLTRIM(LEFT(拼音,1))),PROPER(ALLTRIM(拼音)))
ENDCASE
USE IN SELECT([TEMP])
ELSE
CPY=CPY+SUBSTRC(ALLTRIM(CSTR),I,1)
ENDIF
ENDFOR
RETURN CPY