汉字转换拼音,求指导
本人需要写一个汉字转换拼音的程序,不知道有没有人能给个思路?
[解决办法]
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
?GetPY('十豆三')&& 得到的结果为 SDS
Function GetPY
Parameters cChina
Local pcPychr,i,j,c,Hz
Release pcPychr
Public pcPychr
pcPychr=''
Set Collate To 'Pinyin'
Pycode='八嚓咑妸发旮铪讥讥咔垃呣拿讴趴七呥仨他哇哇哇夕丫匝咗' &&从B开始的每个拼音码的首字码
For i=1 To Len(cChina)
If Asc(Substr(cChina,i,1))>160
hz=Substr(cChina,i,2)
c=''
s=1
For j=1 To 52
s1=Substr(Pycode,j,2)
If hz<Substr(Pycode,j,2)
c=Chr(96+S)
Exit
Endif
j=j+1
s=s+1
Endfor
pcPychr=pcPychr+Upper(c)
i=i+1
Else
pcPychr=pcPychr+Upper(Substr(cChina,i,1))
Endif
Endfor
Return pcPychr
Endfunc