经如说这个字串"谢谢你"经过这个函数处理之后变成"xxn"呢?
谢谢
16 个解决方案
#1
有人做过吗?
#2
没做过,可能需要汉字库的支持吧?或者你自己也要建个字典之类的,没有对应关系无法实现。
#3
巨难呦!
碰到我你走运了 我找了好久的
unit PYCode;
(*
Copyright (C) Trueway(TM) 6, 1999 - 3, 2000, All rights reserved.
Trueway(TM) is the trademark of programs by LiQunwei
外挂式输入码生成器 Version 4.0
Created On: 06/05/1999
Last Update: 03/23/2000
调用示例:
...
First;
while not EOF do begin
Edit;
FieldByName(PyFieldName).AsString :=
String(MakePyCode(FieldByName(ChnFieldName).AsString, 1, 6);
Next;
end;
...
*)
interface
function MakeSpellCode(stText: string; iMode, iCount: Integer): string;
{ iMode 二进制功能位说明
X X X X X X X X X X X X X X X X
3 2 1
1: 0 - 只取各个汉字声母的第一个字母; 1 - 全取
2: 0 - 遇到不能翻译的字符不翻译; 1 - 翻译成 '?' (本选项目针对全角字符)
3: 0 - 生成的串不包括非数字, 字母的其他字符; 1 - 包括
(控制全角的要输出非数字, 字母字符的; 半角的非数字, 字母字符)
请在调用之前调用 LoadIMCode 函数
}
function GetSpellCode(szText: PChar; iMode, iCount: Integer): PChar; stdcall;
function LoadIMCode(as_dict_file: PChar): integer; stdcall;
// 切换输入码数据源
// 调用示例: LoadIMCode('winpy.txt');
// 此函数只需在切换字典数据时使用
function UseInplace: integer; stdcall;
// 使用内置拼音代码字典
function UseOutplace: integer; stdcall;
// 使用外置拼音代码字典
function IsOutplace: integer; stdcall;
// 是否外置
implementation
uses
SysUtils;
type
{ 拼音代码表 }
TPYCode = record
PYCode: string[6];
end;
TFPYCodes = array [1..126, 1..191] of TPYCode;
var
ImCodes: TFPYCodes;
gi_loaded: integer =0;
const
PYMUSICCOUNT = 405;
PyMusicCode: array [1..PYMUSICCOUNT] of string[6] = { 汉字基本发音表 } (
'a', 'ai', 'an', 'ang', 'ao', 'ba', 'bai', 'ban', 'bang', 'bao',
'bei', 'ben', 'beng', 'bi', 'bian', 'biao', 'bie', 'bin', 'bing', 'bo',
'bu', 'ca', 'cai', 'can', 'cang', 'cao', 'ce', 'ceng', 'cha', 'chai',
'chan', 'chang', 'chao', 'che', 'chen', 'cheng', 'chi', 'chong', 'chou', 'chu',
'chuai', 'chuan', 'chuang', 'chui', 'chun', 'chuo', 'ci', 'cong', 'cou', 'cu',
'cuan', 'cui', 'cun', 'cuo', 'da', 'dai', 'dan', 'dang', 'dao', 'de',
'deng', 'di', 'dian', 'diao', 'die', 'ding', 'diu', 'dong', 'dou', 'du',
'duan', 'dui', 'dun', 'duo', 'e', 'en', 'er', 'fa', 'fan', 'fang',
'fei', 'fen', 'feng', 'fu', 'fou', 'ga', 'gai', 'gan', 'gang', 'gao',
'ge', 'ji', 'gen', 'geng', 'gong', 'gou', 'gu', 'gua', 'guai', 'guan',
'guang', 'gui', 'gun', 'guo', 'ha', 'hai', 'han', 'hang', 'hao', 'he',
'hei', 'hen', 'heng', 'hong', 'hou', 'hu', 'hua', 'huai', 'huan', 'huang',
'hui', 'hun', 'huo', 'jia', 'jian', 'jiang', 'qiao', 'jiao', 'jie', 'jin',
'jing', 'jiong', 'jiu', 'ju', 'juan', 'jue', 'jun', 'ka', 'kai', 'kan',
'kang', 'kao', 'ke', 'ken', 'keng', 'kong', 'kou', 'ku', 'kua', 'kuai',
'kuan', 'kuang', 'kui', 'kun', 'kuo', 'la', 'lai', 'lan', 'lang', 'lao',
'le', 'lei', 'leng', 'li', 'lia', 'lian', 'liang', 'liao', 'lie', 'lin',
'ling', 'liu', 'long', 'lou', 'lu', 'luan', 'lue', 'lun', 'luo', 'ma',
'mai', 'man', 'mang', 'mao', 'me', 'mei', 'men', 'meng', 'mi', 'mian',
'miao', 'mie', 'min', 'ming', 'miu', 'mo', 'mou', 'mu', 'na', 'nai',
'nan', 'nang', 'nao', 'ne', 'nei', 'nen', 'neng', 'ni', 'nian', 'niang',
'niao', 'nie', 'nin', 'ning', 'niu', 'nong', 'nu', 'nuan', 'nue', 'yao',
'nuo', 'o', 'ou', 'pa', 'pai', 'pan', 'pang', 'pao', 'pei', 'pen',
'peng', 'pi', 'pian', 'piao', 'pie', 'pin', 'ping', 'po', 'pou', 'pu',
'qi', 'qia', 'qian', 'qiang', 'qie', 'qin', 'qing', 'qiong', 'qiu', 'qu',
'quan', 'que', 'qun', 'ran', 'rang', 'rao', 're', 'ren', 'reng', 'ri',
'rong', 'rou', 'ru', 'ruan', 'rui', 'run', 'ruo', 'sa', 'sai', 'san',
'sang', 'sao', 'se', 'sen', 'seng', 'sha', 'shai', 'shan', 'shang', 'shao',
'she', 'shen', 'sheng', 'shi', 'shou', 'shu', 'shua', 'shuai', 'shuan', 'shuang',
'shui', 'shun', 'shuo', 'si', 'song', 'sou', 'su', 'suan', 'sui', 'sun',
'suo', 'ta', 'tai', 'tan', 'tang', 'tao', 'te', 'teng', 'ti', 'tian',
'tiao', 'tie', 'ting', 'tong', 'tou', 'tu', 'tuan', 'tui', 'tun', 'tuo',
'wa', 'wai', 'wan', 'wang', 'wei', 'wen', 'weng', 'wo', 'wu', 'xi',
'xia', 'xian', 'xiang', 'xiao', 'xie', 'xin', 'xing', 'xiong', 'xiu', 'xu',
'xuan', 'xue', 'xun', 'ya', 'yan', 'yang', 'ye', 'yi', 'yin', 'ying',
'yo', 'yong', 'you', 'yu', 'yuan', 'yue', 'yun', 'za', 'zai', 'zan',
'zang', 'zao', 'ze', 'zei', 'zen', 'zeng', 'zha', 'zhai', 'zhan', 'zhang',
'zhao', 'zhe', 'zhen', 'zheng', 'zhi', 'zhong', 'zhou', 'zhu', 'zhua', 'zhuai',
'zhuan', 'zhuang', 'zhui', 'zhun', 'zhuo', 'zi', 'zong', 'zou', 'zu', 'zuan',
'zui', 'zun', 'zuo', '', 'ei', 'm', 'n', 'dia', 'cen', 'nou',
'jv', 'qv', 'xv', 'lv', 'nv'
);
PyCodeIndex: array [1..126, 1..191] of Word = ( { 拼音索引表 }
碰到我你走运了 我找了好久的
unit PYCode;
(*
Copyright (C) Trueway(TM) 6, 1999 - 3, 2000, All rights reserved.
Trueway(TM) is the trademark of programs by LiQunwei
外挂式输入码生成器 Version 4.0
Created On: 06/05/1999
Last Update: 03/23/2000
调用示例:
...
First;
while not EOF do begin
Edit;
FieldByName(PyFieldName).AsString :=
String(MakePyCode(FieldByName(ChnFieldName).AsString, 1, 6);
Next;
end;
...
*)
interface
function MakeSpellCode(stText: string; iMode, iCount: Integer): string;
{ iMode 二进制功能位说明
X X X X X X X X X X X X X X X X
3 2 1
1: 0 - 只取各个汉字声母的第一个字母; 1 - 全取
2: 0 - 遇到不能翻译的字符不翻译; 1 - 翻译成 '?' (本选项目针对全角字符)
3: 0 - 生成的串不包括非数字, 字母的其他字符; 1 - 包括
(控制全角的要输出非数字, 字母字符的; 半角的非数字, 字母字符)
请在调用之前调用 LoadIMCode 函数
}
function GetSpellCode(szText: PChar; iMode, iCount: Integer): PChar; stdcall;
function LoadIMCode(as_dict_file: PChar): integer; stdcall;
// 切换输入码数据源
// 调用示例: LoadIMCode('winpy.txt');
// 此函数只需在切换字典数据时使用
function UseInplace: integer; stdcall;
// 使用内置拼音代码字典
function UseOutplace: integer; stdcall;
// 使用外置拼音代码字典
function IsOutplace: integer; stdcall;
// 是否外置
implementation
uses
SysUtils;
type
{ 拼音代码表 }
TPYCode = record
PYCode: string[6];
end;
TFPYCodes = array [1..126, 1..191] of TPYCode;
var
ImCodes: TFPYCodes;
gi_loaded: integer =0;
const
PYMUSICCOUNT = 405;
PyMusicCode: array [1..PYMUSICCOUNT] of string[6] = { 汉字基本发音表 } (
'a', 'ai', 'an', 'ang', 'ao', 'ba', 'bai', 'ban', 'bang', 'bao',
'bei', 'ben', 'beng', 'bi', 'bian', 'biao', 'bie', 'bin', 'bing', 'bo',
'bu', 'ca', 'cai', 'can', 'cang', 'cao', 'ce', 'ceng', 'cha', 'chai',
'chan', 'chang', 'chao', 'che', 'chen', 'cheng', 'chi', 'chong', 'chou', 'chu',
'chuai', 'chuan', 'chuang', 'chui', 'chun', 'chuo', 'ci', 'cong', 'cou', 'cu',
'cuan', 'cui', 'cun', 'cuo', 'da', 'dai', 'dan', 'dang', 'dao', 'de',
'deng', 'di', 'dian', 'diao', 'die', 'ding', 'diu', 'dong', 'dou', 'du',
'duan', 'dui', 'dun', 'duo', 'e', 'en', 'er', 'fa', 'fan', 'fang',
'fei', 'fen', 'feng', 'fu', 'fou', 'ga', 'gai', 'gan', 'gang', 'gao',
'ge', 'ji', 'gen', 'geng', 'gong', 'gou', 'gu', 'gua', 'guai', 'guan',
'guang', 'gui', 'gun', 'guo', 'ha', 'hai', 'han', 'hang', 'hao', 'he',
'hei', 'hen', 'heng', 'hong', 'hou', 'hu', 'hua', 'huai', 'huan', 'huang',
'hui', 'hun', 'huo', 'jia', 'jian', 'jiang', 'qiao', 'jiao', 'jie', 'jin',
'jing', 'jiong', 'jiu', 'ju', 'juan', 'jue', 'jun', 'ka', 'kai', 'kan',
'kang', 'kao', 'ke', 'ken', 'keng', 'kong', 'kou', 'ku', 'kua', 'kuai',
'kuan', 'kuang', 'kui', 'kun', 'kuo', 'la', 'lai', 'lan', 'lang', 'lao',
'le', 'lei', 'leng', 'li', 'lia', 'lian', 'liang', 'liao', 'lie', 'lin',
'ling', 'liu', 'long', 'lou', 'lu', 'luan', 'lue', 'lun', 'luo', 'ma',
'mai', 'man', 'mang', 'mao', 'me', 'mei', 'men', 'meng', 'mi', 'mian',
'miao', 'mie', 'min', 'ming', 'miu', 'mo', 'mou', 'mu', 'na', 'nai',
'nan', 'nang', 'nao', 'ne', 'nei', 'nen', 'neng', 'ni', 'nian', 'niang',
'niao', 'nie', 'nin', 'ning', 'niu', 'nong', 'nu', 'nuan', 'nue', 'yao',
'nuo', 'o', 'ou', 'pa', 'pai', 'pan', 'pang', 'pao', 'pei', 'pen',
'peng', 'pi', 'pian', 'piao', 'pie', 'pin', 'ping', 'po', 'pou', 'pu',
'qi', 'qia', 'qian', 'qiang', 'qie', 'qin', 'qing', 'qiong', 'qiu', 'qu',
'quan', 'que', 'qun', 'ran', 'rang', 'rao', 're', 'ren', 'reng', 'ri',
'rong', 'rou', 'ru', 'ruan', 'rui', 'run', 'ruo', 'sa', 'sai', 'san',
'sang', 'sao', 'se', 'sen', 'seng', 'sha', 'shai', 'shan', 'shang', 'shao',
'she', 'shen', 'sheng', 'shi', 'shou', 'shu', 'shua', 'shuai', 'shuan', 'shuang',
'shui', 'shun', 'shuo', 'si', 'song', 'sou', 'su', 'suan', 'sui', 'sun',
'suo', 'ta', 'tai', 'tan', 'tang', 'tao', 'te', 'teng', 'ti', 'tian',
'tiao', 'tie', 'ting', 'tong', 'tou', 'tu', 'tuan', 'tui', 'tun', 'tuo',
'wa', 'wai', 'wan', 'wang', 'wei', 'wen', 'weng', 'wo', 'wu', 'xi',
'xia', 'xian', 'xiang', 'xiao', 'xie', 'xin', 'xing', 'xiong', 'xiu', 'xu',
'xuan', 'xue', 'xun', 'ya', 'yan', 'yang', 'ye', 'yi', 'yin', 'ying',
'yo', 'yong', 'you', 'yu', 'yuan', 'yue', 'yun', 'za', 'zai', 'zan',
'zang', 'zao', 'ze', 'zei', 'zen', 'zeng', 'zha', 'zhai', 'zhan', 'zhang',
'zhao', 'zhe', 'zhen', 'zheng', 'zhi', 'zhong', 'zhou', 'zhu', 'zhua', 'zhuai',
'zhuan', 'zhuang', 'zhui', 'zhun', 'zhuo', 'zi', 'zong', 'zou', 'zu', 'zuan',
'zui', 'zun', 'zuo', '', 'ei', 'm', 'n', 'dia', 'cen', 'nou',
'jv', 'qv', 'xv', 'lv', 'nv'
);
PyCodeIndex: array [1..126, 1..191] of Word = ( { 拼音索引表 }
#4
CharIndex: array [1..94] of string[2] = ( { 罗马数字 }
'1','2','3','4','5','6','7','8','9','10','','','','','','',
'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20',
'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20',
'1','2','3','4','5','6','7','8','9','10','','',
'1','2','3','4','5','6','7','8','9','10','','',
'1','2','3','4','5','6','7','8','9','10','11','12','',''
);
CharIndex2: array [1..24] of string[2] = ( { 希腊字母 }
'a','b','g','d','e','z','e','th','i','k','l','m','n','x','o','p','r',
's','t','u','ph','kh','ps','o'
);
// Pascal -> PChar
// 直接使用 PChar 转化有时会转化出错
function StrPch(const stPas: string): PChar;
begin
// Result := '';
GetMem(Result, Length(stPas) + 1);
StrPCopy(Result, stPas);
end;
function MakeSpellCode(stText: string; iMode, iCount: Integer): string;
var
i, Index: integer;
APy, ls_code: string;
fFlag1, fFlag2, fFlag3: Boolean;
begin
fFlag1 := (iMode and $0001) = 1;
fFlag2 := (iMode and $0002) = 2;
fFlag3 := (iMode and $0004) = 4;
Result := '';
if iMode < 0 then Exit;
i := 1;
while (i <= Length(stText)) do begin
if (Ord(stText[i]) >= 129) and (Ord(stText[i + 1]) >= 64) then begin
// 是否为 GBK 字符
case Ord(stText[i]) of
163: // 全角 ASCII
begin
APy := Chr(Ord(stText[i + 1]) - 128);
// 控制不能输出非数字, 字母的字符
if not fFlag3 and not (APy[1] in ['a'..'z', 'A'..'Z', '0'..'9']) then
APy := '';
end;
162: // 罗马数字
if Ord(stText[i + 1]) > 160 then
APy := CharIndex[Ord(stText[i + 1]) - 160] else
// 在罗马数字区, 不能翻译的字符非罗马数字
if fFlag2 then APy := '?' else APy := '';
166: // 希腊字母
if Ord(stText[i + 1]) in [$A1..$B8] then
APy := UpperCase(CharIndex2[Ord(stText[i + 1]) - $A0])
else if Ord(stText[i + 1]) in [$C1..$D8] then
APy := UpperCase(CharIndex2[Ord(stText[i + 1]) - $C0]);
else // 一般汉字
if gi_loaded = 1 then begin // 使用外挂
// 获得拼音索引
ls_code := IMCodes[Ord(stText[i]) - 128, Ord(stText[i + 1]) - 63].PYCode;
if not fFlag1 then // iFlag1 = False, 是单拼音
APy := Copy(Uppercase(ls_code), 1, 1) else
APy := Copy(Uppercase(ls_code), 1, 6);
end else begin // 使用内置
// 获得拼音索引
Index := PyCodeIndex[Ord(stText[i]) - 128, Ord(stText[i + 1]) - 63];
if Index = 0 then // 无此汉字, 不能翻译的字符, GBK 保留
if fFlag2 then APy := '?' else APy := ''
else if not fFlag1 then // iFlag1 = False, 是单拼音
APy := Copy(Uppercase(PyMusicCode[Index]), 1, 1) else
APy := Copy(Uppercase(PyMusicCode[Index]), 1, 6);
end;
end;
Result := Result + APy;
Inc(i, 2);
end else begin // 在 GBK 字符集外, 即半角字符
if fFlag3 or (stText[i] in ['a'..'z', 'A'..'Z', '0'..'9']) then
Result := Result + UpperCase(stText[i]);
Inc(i);
end;
end;
Result := Copy(Result, 1, iCount);
end;
function GetSpellCode(szText: PChar; iMode, iCount: Integer): PChar;
// Call MakeSpellCode
begin
Result := StrPch(MakeSpellCode(String(szText), iMode, iCount));
end;
function LoadIMCode(as_dict_file: PChar): integer;
// 切换字典
var
SpacePos, L, I, J :Integer;
//index: Integer;
PYCode: string[6];
ls_dict_file, LineStr: string;
SrcFp: TextFile; { 汉字输入法代码字典文件 }
begin
gi_loaded := 1;
ls_dict_file := string(as_dict_file);
result := 0;
for J := 1 to 126 do { 初始化处理 }
for I := 1 to 191 do ImCodes[J, I].PYCode := '';
try
try
AssignFile(SrcFp, ls_dict_file);
Reset(SrcFp);
while not EOF(SrcFp) do begin
ReadLn(SrcFp, LineStr);
if (Ord(LineStr[1]) >= 129) and (Ord(LineStr[2]) >= 64)
{ GBK 内码区间: 首字节: $81 - $FE
尾字节: $40 - $7E, $80 - $FE }
and (LineStr[3] in ['0'..'9', 'A'..'Z', 'a'..'z']) then begin
SpacePos := Pos(' ', LineStr);
if SpacePos = 0 then // 单音字
PYCode := Copy(LineStr, 3, 6) // 取拼音代码
else begin // 多音字
L := Length(LineStr);
PYCode := Copy(LineStr, SpacePos + 1, L - SpacePos); // 取常用拼音代码
end;
ImCodes[Ord(LineStr[1]) - 128, Ord(LineStr[2]) - 63].PYCode := PYCode;
end;
end;
result := 1;
finally
CloseFile(SrcFp);
end;
except
end;
end;
function UseInplace: integer;
begin
gi_loaded := 0;
result := 0;
end;
function UseOutplace: integer;
begin
gi_loaded := 1;
result := 1;
end;
function IsOutplace: integer;
begin
result := gi_loaded;
end;
end.
'1','2','3','4','5','6','7','8','9','10','','','','','','',
'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20',
'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20',
'1','2','3','4','5','6','7','8','9','10','','',
'1','2','3','4','5','6','7','8','9','10','','',
'1','2','3','4','5','6','7','8','9','10','11','12','',''
);
CharIndex2: array [1..24] of string[2] = ( { 希腊字母 }
'a','b','g','d','e','z','e','th','i','k','l','m','n','x','o','p','r',
's','t','u','ph','kh','ps','o'
);
// Pascal -> PChar
// 直接使用 PChar 转化有时会转化出错
function StrPch(const stPas: string): PChar;
begin
// Result := '';
GetMem(Result, Length(stPas) + 1);
StrPCopy(Result, stPas);
end;
function MakeSpellCode(stText: string; iMode, iCount: Integer): string;
var
i, Index: integer;
APy, ls_code: string;
fFlag1, fFlag2, fFlag3: Boolean;
begin
fFlag1 := (iMode and $0001) = 1;
fFlag2 := (iMode and $0002) = 2;
fFlag3 := (iMode and $0004) = 4;
Result := '';
if iMode < 0 then Exit;
i := 1;
while (i <= Length(stText)) do begin
if (Ord(stText[i]) >= 129) and (Ord(stText[i + 1]) >= 64) then begin
// 是否为 GBK 字符
case Ord(stText[i]) of
163: // 全角 ASCII
begin
APy := Chr(Ord(stText[i + 1]) - 128);
// 控制不能输出非数字, 字母的字符
if not fFlag3 and not (APy[1] in ['a'..'z', 'A'..'Z', '0'..'9']) then
APy := '';
end;
162: // 罗马数字
if Ord(stText[i + 1]) > 160 then
APy := CharIndex[Ord(stText[i + 1]) - 160] else
// 在罗马数字区, 不能翻译的字符非罗马数字
if fFlag2 then APy := '?' else APy := '';
166: // 希腊字母
if Ord(stText[i + 1]) in [$A1..$B8] then
APy := UpperCase(CharIndex2[Ord(stText[i + 1]) - $A0])
else if Ord(stText[i + 1]) in [$C1..$D8] then
APy := UpperCase(CharIndex2[Ord(stText[i + 1]) - $C0]);
else // 一般汉字
if gi_loaded = 1 then begin // 使用外挂
// 获得拼音索引
ls_code := IMCodes[Ord(stText[i]) - 128, Ord(stText[i + 1]) - 63].PYCode;
if not fFlag1 then // iFlag1 = False, 是单拼音
APy := Copy(Uppercase(ls_code), 1, 1) else
APy := Copy(Uppercase(ls_code), 1, 6);
end else begin // 使用内置
// 获得拼音索引
Index := PyCodeIndex[Ord(stText[i]) - 128, Ord(stText[i + 1]) - 63];
if Index = 0 then // 无此汉字, 不能翻译的字符, GBK 保留
if fFlag2 then APy := '?' else APy := ''
else if not fFlag1 then // iFlag1 = False, 是单拼音
APy := Copy(Uppercase(PyMusicCode[Index]), 1, 1) else
APy := Copy(Uppercase(PyMusicCode[Index]), 1, 6);
end;
end;
Result := Result + APy;
Inc(i, 2);
end else begin // 在 GBK 字符集外, 即半角字符
if fFlag3 or (stText[i] in ['a'..'z', 'A'..'Z', '0'..'9']) then
Result := Result + UpperCase(stText[i]);
Inc(i);
end;
end;
Result := Copy(Result, 1, iCount);
end;
function GetSpellCode(szText: PChar; iMode, iCount: Integer): PChar;
// Call MakeSpellCode
begin
Result := StrPch(MakeSpellCode(String(szText), iMode, iCount));
end;
function LoadIMCode(as_dict_file: PChar): integer;
// 切换字典
var
SpacePos, L, I, J :Integer;
//index: Integer;
PYCode: string[6];
ls_dict_file, LineStr: string;
SrcFp: TextFile; { 汉字输入法代码字典文件 }
begin
gi_loaded := 1;
ls_dict_file := string(as_dict_file);
result := 0;
for J := 1 to 126 do { 初始化处理 }
for I := 1 to 191 do ImCodes[J, I].PYCode := '';
try
try
AssignFile(SrcFp, ls_dict_file);
Reset(SrcFp);
while not EOF(SrcFp) do begin
ReadLn(SrcFp, LineStr);
if (Ord(LineStr[1]) >= 129) and (Ord(LineStr[2]) >= 64)
{ GBK 内码区间: 首字节: $81 - $FE
尾字节: $40 - $7E, $80 - $FE }
and (LineStr[3] in ['0'..'9', 'A'..'Z', 'a'..'z']) then begin
SpacePos := Pos(' ', LineStr);
if SpacePos = 0 then // 单音字
PYCode := Copy(LineStr, 3, 6) // 取拼音代码
else begin // 多音字
L := Length(LineStr);
PYCode := Copy(LineStr, SpacePos + 1, L - SpacePos); // 取常用拼音代码
end;
ImCodes[Ord(LineStr[1]) - 128, Ord(LineStr[2]) - 63].PYCode := PYCode;
end;
end;
result := 1;
finally
CloseFile(SrcFp);
end;
except
end;
end;
function UseInplace: integer;
begin
gi_loaded := 0;
result := 0;
end;
function UseOutplace: integer;
begin
gi_loaded := 1;
result := 1;
end;
function IsOutplace: integer;
begin
result := gi_loaded;
end;
end.
#5
不行贴不下 呵呵
我发到我的网站上你去下载吧
http://nullspace.cnwindows.com
#6
谢了,马上去看看
#7
以前改过一个DELPHI的代码,很乱,希望有帮助
//---------------------------------------------------------------------------
unsigned char GetPYIndexChar( AnsiString str_test)
{
unsigned char Buffer[2];
unsigned char Return_char = 0 ;
Word In_code = 0x00;
int i;
for ( i = 0 ; i < 2 ; i++ )
{
Buffer[i] = 0x00;
}
unsigned char *p;
p = (unsigned char*)str_test.c_str();
for ( i = 0 ; i < 2 ; i++ )
{
Buffer[i] = (unsigned char)*p ;
p++;
}
Word Left_eight = Word(Buffer[0]) << 8;
Word Right_right = Word(Buffer[1]) ;
In_code = Left_eight + Right_right ;
if ( ( In_code >= 0xB0A1 ) && ( In_code <= 0xB0C4 ) )
{
Return_char = 'A' ;
}
else if ( ( In_code >= 0xB0C5 ) && ( In_code <= 0xB2C0 ) )
{
Return_char = 'B' ;
}
else if ( ( In_code >= 0xB2C1 ) && ( In_code <= 0xB4ED ) )
{
Return_char = 'C' ;
}
else if ( ( In_code >= 0xB4EE ) && ( In_code <= 0xB6E9 ) )
{
Return_char = 'D' ;
}
else if ( ( In_code >= 0xB6EA ) && ( In_code <= 0xB7A1 ) )
{
Return_char = 'E' ;
}
else if ( ( In_code >= 0xB7A2 ) && ( In_code <= 0xB8C0 ) )
{
Return_char = 'F' ;
}
else if ( ( In_code >= 0xB8C1 ) && ( In_code <= 0xB9FD ) )
{
Return_char = 'G' ;
}
else if ( ( In_code >= 0xB9FE ) && ( In_code <= 0xBBF6 ) )
{
Return_char = 'H' ;
}
else if ( ( In_code >= 0xBBF7 ) && ( In_code <= 0xBFA5 ) )
{
Return_char = 'J' ;
}
else if ( ( In_code >= 0xBFA6 ) && ( In_code <= 0xC0AB ) )
{
Return_char = 'K' ;
}
else if ( ( In_code >= 0xC0AC ) && ( In_code <= 0xC2E7 ) )
{
Return_char = 'L' ;
}
else if ( ( In_code >= 0xC2E8 ) && ( In_code <= 0xC4C2 ) )
{
Return_char = 'M' ;
}
else if ( ( In_code >= 0xC4C3 ) && ( In_code <= 0xC5B5 ) )
{
Return_char = 'N' ;
}
else if ( ( In_code >= 0xC5B6 ) && ( In_code <= 0xC5BD ) )
{
Return_char = 'O' ;
}
else if ( ( In_code >= 0xC5BE ) && ( In_code <= 0xC6D9 ) )
{
Return_char = 'P' ;
}
else if ( ( In_code >= 0xC6DA ) && ( In_code <= 0xC8BA ) )
{
Return_char = 'Q' ;
}
else if ( ( In_code >= 0xC8BB ) && ( In_code <= 0xC8F5 ) )
{
Return_char = 'R' ;
}
else if ( ( In_code >= 0xC8F6 ) && ( In_code <= 0xCBF9 ) )
{
Return_char = 'S' ;
}
else if ( ( In_code >= 0xCBFA ) && ( In_code <= 0xCDD9 ) )
{
Return_char = 'T' ;
}
else if ( ( In_code >= 0xCDDA ) && ( In_code <= 0xCEF3 ) )
{
Return_char = 'W' ;
}
else if ( ( In_code >= 0xCEF4 ) && ( In_code <= 0xD188 ) )
{
Return_char = 'X' ;
}
else if ( ( In_code >= 0xD1B9 ) && ( In_code <= 0xD4D0 ) )
{
Return_char = 'Y' ;
}
else if ( ( In_code >= 0xD4D1 ) && ( In_code <= 0xD7F9 ) )
{
Return_char = 'Z' ;
}
else
{
Return_char = 0 ;
}
return Return_char ;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
unsigned char GetPYIndexChar( AnsiString str_test)
{
unsigned char Buffer[2];
unsigned char Return_char = 0 ;
Word In_code = 0x00;
int i;
for ( i = 0 ; i < 2 ; i++ )
{
Buffer[i] = 0x00;
}
unsigned char *p;
p = (unsigned char*)str_test.c_str();
for ( i = 0 ; i < 2 ; i++ )
{
Buffer[i] = (unsigned char)*p ;
p++;
}
Word Left_eight = Word(Buffer[0]) << 8;
Word Right_right = Word(Buffer[1]) ;
In_code = Left_eight + Right_right ;
if ( ( In_code >= 0xB0A1 ) && ( In_code <= 0xB0C4 ) )
{
Return_char = 'A' ;
}
else if ( ( In_code >= 0xB0C5 ) && ( In_code <= 0xB2C0 ) )
{
Return_char = 'B' ;
}
else if ( ( In_code >= 0xB2C1 ) && ( In_code <= 0xB4ED ) )
{
Return_char = 'C' ;
}
else if ( ( In_code >= 0xB4EE ) && ( In_code <= 0xB6E9 ) )
{
Return_char = 'D' ;
}
else if ( ( In_code >= 0xB6EA ) && ( In_code <= 0xB7A1 ) )
{
Return_char = 'E' ;
}
else if ( ( In_code >= 0xB7A2 ) && ( In_code <= 0xB8C0 ) )
{
Return_char = 'F' ;
}
else if ( ( In_code >= 0xB8C1 ) && ( In_code <= 0xB9FD ) )
{
Return_char = 'G' ;
}
else if ( ( In_code >= 0xB9FE ) && ( In_code <= 0xBBF6 ) )
{
Return_char = 'H' ;
}
else if ( ( In_code >= 0xBBF7 ) && ( In_code <= 0xBFA5 ) )
{
Return_char = 'J' ;
}
else if ( ( In_code >= 0xBFA6 ) && ( In_code <= 0xC0AB ) )
{
Return_char = 'K' ;
}
else if ( ( In_code >= 0xC0AC ) && ( In_code <= 0xC2E7 ) )
{
Return_char = 'L' ;
}
else if ( ( In_code >= 0xC2E8 ) && ( In_code <= 0xC4C2 ) )
{
Return_char = 'M' ;
}
else if ( ( In_code >= 0xC4C3 ) && ( In_code <= 0xC5B5 ) )
{
Return_char = 'N' ;
}
else if ( ( In_code >= 0xC5B6 ) && ( In_code <= 0xC5BD ) )
{
Return_char = 'O' ;
}
else if ( ( In_code >= 0xC5BE ) && ( In_code <= 0xC6D9 ) )
{
Return_char = 'P' ;
}
else if ( ( In_code >= 0xC6DA ) && ( In_code <= 0xC8BA ) )
{
Return_char = 'Q' ;
}
else if ( ( In_code >= 0xC8BB ) && ( In_code <= 0xC8F5 ) )
{
Return_char = 'R' ;
}
else if ( ( In_code >= 0xC8F6 ) && ( In_code <= 0xCBF9 ) )
{
Return_char = 'S' ;
}
else if ( ( In_code >= 0xCBFA ) && ( In_code <= 0xCDD9 ) )
{
Return_char = 'T' ;
}
else if ( ( In_code >= 0xCDDA ) && ( In_code <= 0xCEF3 ) )
{
Return_char = 'W' ;
}
else if ( ( In_code >= 0xCEF4 ) && ( In_code <= 0xD188 ) )
{
Return_char = 'X' ;
}
else if ( ( In_code >= 0xD1B9 ) && ( In_code <= 0xD4D0 ) )
{
Return_char = 'Y' ;
}
else if ( ( In_code >= 0xD4D1 ) && ( In_code <= 0xD7F9 ) )
{
Return_char = 'Z' ;
}
else
{
Return_char = 0 ;
}
return Return_char ;
}
//---------------------------------------------------------------------------
#8
续。
AnsiString SearchByPYIndexStr( TStrings *SourceStrs , AnsiString PYIndexStr)
{
int i = 0 ;
int j = 0 ;
AnsiString hzchar = "" ;
bool Find_ok = true ;
AnsiString result = "" ;
unsigned char *p_hzchar;
p_hzchar = PYIndexStr.c_str();
if ( p_hzchar[0] <= 127 )
{
for ( i = 0 ; i <= SourceStrs->Count - 1 ; i++ )
{
Find_ok = true ;
AnsiString str_hang = "" ;
for ( j = 0 ; j < PYIndexStr.Length() ; j++ )
{
str_hang = SourceStrs->Strings[i];
hzchar = str_hang.SubString( 2 * j + 1 , 2 );
AnsiString str_temp = "";
str_temp = AnsiString(char(p_hzchar[j]));
if (( str_hang.SubString( j + 1 , 1 ).UpperCase() != PYIndexStr.SubString( j + 1 , 1 ).UpperCase()) && (p_hzchar[j] != '?')&& (str_temp.UpperCase() != AnsiString(char(GetPYIndexChar(hzchar)))))
{
Find_ok = false ;
break;
}
}
if ( Find_ok == true )
{
if ( result == "" )
{
result = SourceStrs->Strings[i];
}
else
{
result = result + char(13) + SourceStrs->Strings[i];
}
}
}
}
else
{
for ( i = 0 ; i <= SourceStrs->Count - 1 ; i++ )
{
Find_ok = true ;
for ( j = 0 ; j < PYIndexStr.Length() / 2 ; j++ )
{
if ( SourceStrs->Strings[i].SubString( 2 * j + 1 , 2 ) != PYIndexStr.SubString( 2 * j + 1 , 2 ) )
{
Find_ok = false ;
break;
}
}
if ( Find_ok == true )
{
if ( result == "" )
{
result = SourceStrs->Strings[i];
}
else
{
result = result + char(13) + SourceStrs->Strings[i];
}
}
}
}
return result ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
if ( SearchByPYIndexStr(ListBox1->Items , Edit1->Text) != "" )
{
ListBox2->Visible = true ;
ListBox2->Items->Text = SearchByPYIndexStr(ListBox1->Items , Edit1->Text) ;
}
else
{
ListBox2->Visible = false ;
}
if ( Edit1->Text == "" )
{
ListBox2->Visible = false ;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ( Key == VK_DOWN && ListBox2->Visible == true )
{
ListBox2->SetFocus();
ListBox2->Selected[0];
ListBox2->Focused();
ListBox2->CanFocus();
ListBox2->Refresh();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox2KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ( Key == VK_BACK || Key == VK_ESCAPE)
{
Edit1->SetFocus();
Edit1->SelStart = Edit1->Text.Length();
}
if ( Key == VK_RETURN )
{
Label1->Caption = ListBox2->Items->Strings[ListBox2->ItemIndex];
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ListBox1->Items->Add("你好") ;
ListBox1->Items->Add("你好吗") ;
ListBox1->Items->Add("谢谢你") ;
ListBox1->Items->Add("谢你") ;
ListBox1->Items->Add("谢谢") ;
ListBox1->Items->Add("aaaa") ;
}
//---------------------------------------------------------------------------
//注:对于生僻字不能查找
AnsiString SearchByPYIndexStr( TStrings *SourceStrs , AnsiString PYIndexStr)
{
int i = 0 ;
int j = 0 ;
AnsiString hzchar = "" ;
bool Find_ok = true ;
AnsiString result = "" ;
unsigned char *p_hzchar;
p_hzchar = PYIndexStr.c_str();
if ( p_hzchar[0] <= 127 )
{
for ( i = 0 ; i <= SourceStrs->Count - 1 ; i++ )
{
Find_ok = true ;
AnsiString str_hang = "" ;
for ( j = 0 ; j < PYIndexStr.Length() ; j++ )
{
str_hang = SourceStrs->Strings[i];
hzchar = str_hang.SubString( 2 * j + 1 , 2 );
AnsiString str_temp = "";
str_temp = AnsiString(char(p_hzchar[j]));
if (( str_hang.SubString( j + 1 , 1 ).UpperCase() != PYIndexStr.SubString( j + 1 , 1 ).UpperCase()) && (p_hzchar[j] != '?')&& (str_temp.UpperCase() != AnsiString(char(GetPYIndexChar(hzchar)))))
{
Find_ok = false ;
break;
}
}
if ( Find_ok == true )
{
if ( result == "" )
{
result = SourceStrs->Strings[i];
}
else
{
result = result + char(13) + SourceStrs->Strings[i];
}
}
}
}
else
{
for ( i = 0 ; i <= SourceStrs->Count - 1 ; i++ )
{
Find_ok = true ;
for ( j = 0 ; j < PYIndexStr.Length() / 2 ; j++ )
{
if ( SourceStrs->Strings[i].SubString( 2 * j + 1 , 2 ) != PYIndexStr.SubString( 2 * j + 1 , 2 ) )
{
Find_ok = false ;
break;
}
}
if ( Find_ok == true )
{
if ( result == "" )
{
result = SourceStrs->Strings[i];
}
else
{
result = result + char(13) + SourceStrs->Strings[i];
}
}
}
}
return result ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
if ( SearchByPYIndexStr(ListBox1->Items , Edit1->Text) != "" )
{
ListBox2->Visible = true ;
ListBox2->Items->Text = SearchByPYIndexStr(ListBox1->Items , Edit1->Text) ;
}
else
{
ListBox2->Visible = false ;
}
if ( Edit1->Text == "" )
{
ListBox2->Visible = false ;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ( Key == VK_DOWN && ListBox2->Visible == true )
{
ListBox2->SetFocus();
ListBox2->Selected[0];
ListBox2->Focused();
ListBox2->CanFocus();
ListBox2->Refresh();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox2KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ( Key == VK_BACK || Key == VK_ESCAPE)
{
Edit1->SetFocus();
Edit1->SelStart = Edit1->Text.Length();
}
if ( Key == VK_RETURN )
{
Label1->Caption = ListBox2->Items->Strings[ListBox2->ItemIndex];
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ListBox1->Items->Add("你好") ;
ListBox1->Items->Add("你好吗") ;
ListBox1->Items->Add("谢谢你") ;
ListBox1->Items->Add("谢你") ;
ListBox1->Items->Add("谢谢") ;
ListBox1->Items->Add("aaaa") ;
}
//---------------------------------------------------------------------------
//注:对于生僻字不能查找
#9
以上是输入拼音查汉字
#10
好啊,我试试
#11
我UP
#12
里面有头文件,OBJ文件呀 include就可以调用了
如:
GetSpellCode(Edit2->Text.c_str(),0,StrLen(Edit2->Text.c_str()));
#13
呵呵!阿星!哪裏找的?
#14
原来是蠱惑兄呀
呵我的收藏
在我的网站
http://nullspace.cnwindows.com可以下
#15
“如何加已有的OBJ文件?”
执行菜单命令[Project]/[Add to Project],然后选择要加的 obj 文件就可以了。
执行菜单命令[Project]/[Add to Project],然后选择要加的 obj 文件就可以了。
#16
关注
#1
有人做过吗?
#2
没做过,可能需要汉字库的支持吧?或者你自己也要建个字典之类的,没有对应关系无法实现。
#3
巨难呦!
碰到我你走运了 我找了好久的
unit PYCode;
(*
Copyright (C) Trueway(TM) 6, 1999 - 3, 2000, All rights reserved.
Trueway(TM) is the trademark of programs by LiQunwei
外挂式输入码生成器 Version 4.0
Created On: 06/05/1999
Last Update: 03/23/2000
调用示例:
...
First;
while not EOF do begin
Edit;
FieldByName(PyFieldName).AsString :=
String(MakePyCode(FieldByName(ChnFieldName).AsString, 1, 6);
Next;
end;
...
*)
interface
function MakeSpellCode(stText: string; iMode, iCount: Integer): string;
{ iMode 二进制功能位说明
X X X X X X X X X X X X X X X X
3 2 1
1: 0 - 只取各个汉字声母的第一个字母; 1 - 全取
2: 0 - 遇到不能翻译的字符不翻译; 1 - 翻译成 '?' (本选项目针对全角字符)
3: 0 - 生成的串不包括非数字, 字母的其他字符; 1 - 包括
(控制全角的要输出非数字, 字母字符的; 半角的非数字, 字母字符)
请在调用之前调用 LoadIMCode 函数
}
function GetSpellCode(szText: PChar; iMode, iCount: Integer): PChar; stdcall;
function LoadIMCode(as_dict_file: PChar): integer; stdcall;
// 切换输入码数据源
// 调用示例: LoadIMCode('winpy.txt');
// 此函数只需在切换字典数据时使用
function UseInplace: integer; stdcall;
// 使用内置拼音代码字典
function UseOutplace: integer; stdcall;
// 使用外置拼音代码字典
function IsOutplace: integer; stdcall;
// 是否外置
implementation
uses
SysUtils;
type
{ 拼音代码表 }
TPYCode = record
PYCode: string[6];
end;
TFPYCodes = array [1..126, 1..191] of TPYCode;
var
ImCodes: TFPYCodes;
gi_loaded: integer =0;
const
PYMUSICCOUNT = 405;
PyMusicCode: array [1..PYMUSICCOUNT] of string[6] = { 汉字基本发音表 } (
'a', 'ai', 'an', 'ang', 'ao', 'ba', 'bai', 'ban', 'bang', 'bao',
'bei', 'ben', 'beng', 'bi', 'bian', 'biao', 'bie', 'bin', 'bing', 'bo',
'bu', 'ca', 'cai', 'can', 'cang', 'cao', 'ce', 'ceng', 'cha', 'chai',
'chan', 'chang', 'chao', 'che', 'chen', 'cheng', 'chi', 'chong', 'chou', 'chu',
'chuai', 'chuan', 'chuang', 'chui', 'chun', 'chuo', 'ci', 'cong', 'cou', 'cu',
'cuan', 'cui', 'cun', 'cuo', 'da', 'dai', 'dan', 'dang', 'dao', 'de',
'deng', 'di', 'dian', 'diao', 'die', 'ding', 'diu', 'dong', 'dou', 'du',
'duan', 'dui', 'dun', 'duo', 'e', 'en', 'er', 'fa', 'fan', 'fang',
'fei', 'fen', 'feng', 'fu', 'fou', 'ga', 'gai', 'gan', 'gang', 'gao',
'ge', 'ji', 'gen', 'geng', 'gong', 'gou', 'gu', 'gua', 'guai', 'guan',
'guang', 'gui', 'gun', 'guo', 'ha', 'hai', 'han', 'hang', 'hao', 'he',
'hei', 'hen', 'heng', 'hong', 'hou', 'hu', 'hua', 'huai', 'huan', 'huang',
'hui', 'hun', 'huo', 'jia', 'jian', 'jiang', 'qiao', 'jiao', 'jie', 'jin',
'jing', 'jiong', 'jiu', 'ju', 'juan', 'jue', 'jun', 'ka', 'kai', 'kan',
'kang', 'kao', 'ke', 'ken', 'keng', 'kong', 'kou', 'ku', 'kua', 'kuai',
'kuan', 'kuang', 'kui', 'kun', 'kuo', 'la', 'lai', 'lan', 'lang', 'lao',
'le', 'lei', 'leng', 'li', 'lia', 'lian', 'liang', 'liao', 'lie', 'lin',
'ling', 'liu', 'long', 'lou', 'lu', 'luan', 'lue', 'lun', 'luo', 'ma',
'mai', 'man', 'mang', 'mao', 'me', 'mei', 'men', 'meng', 'mi', 'mian',
'miao', 'mie', 'min', 'ming', 'miu', 'mo', 'mou', 'mu', 'na', 'nai',
'nan', 'nang', 'nao', 'ne', 'nei', 'nen', 'neng', 'ni', 'nian', 'niang',
'niao', 'nie', 'nin', 'ning', 'niu', 'nong', 'nu', 'nuan', 'nue', 'yao',
'nuo', 'o', 'ou', 'pa', 'pai', 'pan', 'pang', 'pao', 'pei', 'pen',
'peng', 'pi', 'pian', 'piao', 'pie', 'pin', 'ping', 'po', 'pou', 'pu',
'qi', 'qia', 'qian', 'qiang', 'qie', 'qin', 'qing', 'qiong', 'qiu', 'qu',
'quan', 'que', 'qun', 'ran', 'rang', 'rao', 're', 'ren', 'reng', 'ri',
'rong', 'rou', 'ru', 'ruan', 'rui', 'run', 'ruo', 'sa', 'sai', 'san',
'sang', 'sao', 'se', 'sen', 'seng', 'sha', 'shai', 'shan', 'shang', 'shao',
'she', 'shen', 'sheng', 'shi', 'shou', 'shu', 'shua', 'shuai', 'shuan', 'shuang',
'shui', 'shun', 'shuo', 'si', 'song', 'sou', 'su', 'suan', 'sui', 'sun',
'suo', 'ta', 'tai', 'tan', 'tang', 'tao', 'te', 'teng', 'ti', 'tian',
'tiao', 'tie', 'ting', 'tong', 'tou', 'tu', 'tuan', 'tui', 'tun', 'tuo',
'wa', 'wai', 'wan', 'wang', 'wei', 'wen', 'weng', 'wo', 'wu', 'xi',
'xia', 'xian', 'xiang', 'xiao', 'xie', 'xin', 'xing', 'xiong', 'xiu', 'xu',
'xuan', 'xue', 'xun', 'ya', 'yan', 'yang', 'ye', 'yi', 'yin', 'ying',
'yo', 'yong', 'you', 'yu', 'yuan', 'yue', 'yun', 'za', 'zai', 'zan',
'zang', 'zao', 'ze', 'zei', 'zen', 'zeng', 'zha', 'zhai', 'zhan', 'zhang',
'zhao', 'zhe', 'zhen', 'zheng', 'zhi', 'zhong', 'zhou', 'zhu', 'zhua', 'zhuai',
'zhuan', 'zhuang', 'zhui', 'zhun', 'zhuo', 'zi', 'zong', 'zou', 'zu', 'zuan',
'zui', 'zun', 'zuo', '', 'ei', 'm', 'n', 'dia', 'cen', 'nou',
'jv', 'qv', 'xv', 'lv', 'nv'
);
PyCodeIndex: array [1..126, 1..191] of Word = ( { 拼音索引表 }
碰到我你走运了 我找了好久的
unit PYCode;
(*
Copyright (C) Trueway(TM) 6, 1999 - 3, 2000, All rights reserved.
Trueway(TM) is the trademark of programs by LiQunwei
外挂式输入码生成器 Version 4.0
Created On: 06/05/1999
Last Update: 03/23/2000
调用示例:
...
First;
while not EOF do begin
Edit;
FieldByName(PyFieldName).AsString :=
String(MakePyCode(FieldByName(ChnFieldName).AsString, 1, 6);
Next;
end;
...
*)
interface
function MakeSpellCode(stText: string; iMode, iCount: Integer): string;
{ iMode 二进制功能位说明
X X X X X X X X X X X X X X X X
3 2 1
1: 0 - 只取各个汉字声母的第一个字母; 1 - 全取
2: 0 - 遇到不能翻译的字符不翻译; 1 - 翻译成 '?' (本选项目针对全角字符)
3: 0 - 生成的串不包括非数字, 字母的其他字符; 1 - 包括
(控制全角的要输出非数字, 字母字符的; 半角的非数字, 字母字符)
请在调用之前调用 LoadIMCode 函数
}
function GetSpellCode(szText: PChar; iMode, iCount: Integer): PChar; stdcall;
function LoadIMCode(as_dict_file: PChar): integer; stdcall;
// 切换输入码数据源
// 调用示例: LoadIMCode('winpy.txt');
// 此函数只需在切换字典数据时使用
function UseInplace: integer; stdcall;
// 使用内置拼音代码字典
function UseOutplace: integer; stdcall;
// 使用外置拼音代码字典
function IsOutplace: integer; stdcall;
// 是否外置
implementation
uses
SysUtils;
type
{ 拼音代码表 }
TPYCode = record
PYCode: string[6];
end;
TFPYCodes = array [1..126, 1..191] of TPYCode;
var
ImCodes: TFPYCodes;
gi_loaded: integer =0;
const
PYMUSICCOUNT = 405;
PyMusicCode: array [1..PYMUSICCOUNT] of string[6] = { 汉字基本发音表 } (
'a', 'ai', 'an', 'ang', 'ao', 'ba', 'bai', 'ban', 'bang', 'bao',
'bei', 'ben', 'beng', 'bi', 'bian', 'biao', 'bie', 'bin', 'bing', 'bo',
'bu', 'ca', 'cai', 'can', 'cang', 'cao', 'ce', 'ceng', 'cha', 'chai',
'chan', 'chang', 'chao', 'che', 'chen', 'cheng', 'chi', 'chong', 'chou', 'chu',
'chuai', 'chuan', 'chuang', 'chui', 'chun', 'chuo', 'ci', 'cong', 'cou', 'cu',
'cuan', 'cui', 'cun', 'cuo', 'da', 'dai', 'dan', 'dang', 'dao', 'de',
'deng', 'di', 'dian', 'diao', 'die', 'ding', 'diu', 'dong', 'dou', 'du',
'duan', 'dui', 'dun', 'duo', 'e', 'en', 'er', 'fa', 'fan', 'fang',
'fei', 'fen', 'feng', 'fu', 'fou', 'ga', 'gai', 'gan', 'gang', 'gao',
'ge', 'ji', 'gen', 'geng', 'gong', 'gou', 'gu', 'gua', 'guai', 'guan',
'guang', 'gui', 'gun', 'guo', 'ha', 'hai', 'han', 'hang', 'hao', 'he',
'hei', 'hen', 'heng', 'hong', 'hou', 'hu', 'hua', 'huai', 'huan', 'huang',
'hui', 'hun', 'huo', 'jia', 'jian', 'jiang', 'qiao', 'jiao', 'jie', 'jin',
'jing', 'jiong', 'jiu', 'ju', 'juan', 'jue', 'jun', 'ka', 'kai', 'kan',
'kang', 'kao', 'ke', 'ken', 'keng', 'kong', 'kou', 'ku', 'kua', 'kuai',
'kuan', 'kuang', 'kui', 'kun', 'kuo', 'la', 'lai', 'lan', 'lang', 'lao',
'le', 'lei', 'leng', 'li', 'lia', 'lian', 'liang', 'liao', 'lie', 'lin',
'ling', 'liu', 'long', 'lou', 'lu', 'luan', 'lue', 'lun', 'luo', 'ma',
'mai', 'man', 'mang', 'mao', 'me', 'mei', 'men', 'meng', 'mi', 'mian',
'miao', 'mie', 'min', 'ming', 'miu', 'mo', 'mou', 'mu', 'na', 'nai',
'nan', 'nang', 'nao', 'ne', 'nei', 'nen', 'neng', 'ni', 'nian', 'niang',
'niao', 'nie', 'nin', 'ning', 'niu', 'nong', 'nu', 'nuan', 'nue', 'yao',
'nuo', 'o', 'ou', 'pa', 'pai', 'pan', 'pang', 'pao', 'pei', 'pen',
'peng', 'pi', 'pian', 'piao', 'pie', 'pin', 'ping', 'po', 'pou', 'pu',
'qi', 'qia', 'qian', 'qiang', 'qie', 'qin', 'qing', 'qiong', 'qiu', 'qu',
'quan', 'que', 'qun', 'ran', 'rang', 'rao', 're', 'ren', 'reng', 'ri',
'rong', 'rou', 'ru', 'ruan', 'rui', 'run', 'ruo', 'sa', 'sai', 'san',
'sang', 'sao', 'se', 'sen', 'seng', 'sha', 'shai', 'shan', 'shang', 'shao',
'she', 'shen', 'sheng', 'shi', 'shou', 'shu', 'shua', 'shuai', 'shuan', 'shuang',
'shui', 'shun', 'shuo', 'si', 'song', 'sou', 'su', 'suan', 'sui', 'sun',
'suo', 'ta', 'tai', 'tan', 'tang', 'tao', 'te', 'teng', 'ti', 'tian',
'tiao', 'tie', 'ting', 'tong', 'tou', 'tu', 'tuan', 'tui', 'tun', 'tuo',
'wa', 'wai', 'wan', 'wang', 'wei', 'wen', 'weng', 'wo', 'wu', 'xi',
'xia', 'xian', 'xiang', 'xiao', 'xie', 'xin', 'xing', 'xiong', 'xiu', 'xu',
'xuan', 'xue', 'xun', 'ya', 'yan', 'yang', 'ye', 'yi', 'yin', 'ying',
'yo', 'yong', 'you', 'yu', 'yuan', 'yue', 'yun', 'za', 'zai', 'zan',
'zang', 'zao', 'ze', 'zei', 'zen', 'zeng', 'zha', 'zhai', 'zhan', 'zhang',
'zhao', 'zhe', 'zhen', 'zheng', 'zhi', 'zhong', 'zhou', 'zhu', 'zhua', 'zhuai',
'zhuan', 'zhuang', 'zhui', 'zhun', 'zhuo', 'zi', 'zong', 'zou', 'zu', 'zuan',
'zui', 'zun', 'zuo', '', 'ei', 'm', 'n', 'dia', 'cen', 'nou',
'jv', 'qv', 'xv', 'lv', 'nv'
);
PyCodeIndex: array [1..126, 1..191] of Word = ( { 拼音索引表 }
#4
CharIndex: array [1..94] of string[2] = ( { 罗马数字 }
'1','2','3','4','5','6','7','8','9','10','','','','','','',
'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20',
'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20',
'1','2','3','4','5','6','7','8','9','10','','',
'1','2','3','4','5','6','7','8','9','10','','',
'1','2','3','4','5','6','7','8','9','10','11','12','',''
);
CharIndex2: array [1..24] of string[2] = ( { 希腊字母 }
'a','b','g','d','e','z','e','th','i','k','l','m','n','x','o','p','r',
's','t','u','ph','kh','ps','o'
);
// Pascal -> PChar
// 直接使用 PChar 转化有时会转化出错
function StrPch(const stPas: string): PChar;
begin
// Result := '';
GetMem(Result, Length(stPas) + 1);
StrPCopy(Result, stPas);
end;
function MakeSpellCode(stText: string; iMode, iCount: Integer): string;
var
i, Index: integer;
APy, ls_code: string;
fFlag1, fFlag2, fFlag3: Boolean;
begin
fFlag1 := (iMode and $0001) = 1;
fFlag2 := (iMode and $0002) = 2;
fFlag3 := (iMode and $0004) = 4;
Result := '';
if iMode < 0 then Exit;
i := 1;
while (i <= Length(stText)) do begin
if (Ord(stText[i]) >= 129) and (Ord(stText[i + 1]) >= 64) then begin
// 是否为 GBK 字符
case Ord(stText[i]) of
163: // 全角 ASCII
begin
APy := Chr(Ord(stText[i + 1]) - 128);
// 控制不能输出非数字, 字母的字符
if not fFlag3 and not (APy[1] in ['a'..'z', 'A'..'Z', '0'..'9']) then
APy := '';
end;
162: // 罗马数字
if Ord(stText[i + 1]) > 160 then
APy := CharIndex[Ord(stText[i + 1]) - 160] else
// 在罗马数字区, 不能翻译的字符非罗马数字
if fFlag2 then APy := '?' else APy := '';
166: // 希腊字母
if Ord(stText[i + 1]) in [$A1..$B8] then
APy := UpperCase(CharIndex2[Ord(stText[i + 1]) - $A0])
else if Ord(stText[i + 1]) in [$C1..$D8] then
APy := UpperCase(CharIndex2[Ord(stText[i + 1]) - $C0]);
else // 一般汉字
if gi_loaded = 1 then begin // 使用外挂
// 获得拼音索引
ls_code := IMCodes[Ord(stText[i]) - 128, Ord(stText[i + 1]) - 63].PYCode;
if not fFlag1 then // iFlag1 = False, 是单拼音
APy := Copy(Uppercase(ls_code), 1, 1) else
APy := Copy(Uppercase(ls_code), 1, 6);
end else begin // 使用内置
// 获得拼音索引
Index := PyCodeIndex[Ord(stText[i]) - 128, Ord(stText[i + 1]) - 63];
if Index = 0 then // 无此汉字, 不能翻译的字符, GBK 保留
if fFlag2 then APy := '?' else APy := ''
else if not fFlag1 then // iFlag1 = False, 是单拼音
APy := Copy(Uppercase(PyMusicCode[Index]), 1, 1) else
APy := Copy(Uppercase(PyMusicCode[Index]), 1, 6);
end;
end;
Result := Result + APy;
Inc(i, 2);
end else begin // 在 GBK 字符集外, 即半角字符
if fFlag3 or (stText[i] in ['a'..'z', 'A'..'Z', '0'..'9']) then
Result := Result + UpperCase(stText[i]);
Inc(i);
end;
end;
Result := Copy(Result, 1, iCount);
end;
function GetSpellCode(szText: PChar; iMode, iCount: Integer): PChar;
// Call MakeSpellCode
begin
Result := StrPch(MakeSpellCode(String(szText), iMode, iCount));
end;
function LoadIMCode(as_dict_file: PChar): integer;
// 切换字典
var
SpacePos, L, I, J :Integer;
//index: Integer;
PYCode: string[6];
ls_dict_file, LineStr: string;
SrcFp: TextFile; { 汉字输入法代码字典文件 }
begin
gi_loaded := 1;
ls_dict_file := string(as_dict_file);
result := 0;
for J := 1 to 126 do { 初始化处理 }
for I := 1 to 191 do ImCodes[J, I].PYCode := '';
try
try
AssignFile(SrcFp, ls_dict_file);
Reset(SrcFp);
while not EOF(SrcFp) do begin
ReadLn(SrcFp, LineStr);
if (Ord(LineStr[1]) >= 129) and (Ord(LineStr[2]) >= 64)
{ GBK 内码区间: 首字节: $81 - $FE
尾字节: $40 - $7E, $80 - $FE }
and (LineStr[3] in ['0'..'9', 'A'..'Z', 'a'..'z']) then begin
SpacePos := Pos(' ', LineStr);
if SpacePos = 0 then // 单音字
PYCode := Copy(LineStr, 3, 6) // 取拼音代码
else begin // 多音字
L := Length(LineStr);
PYCode := Copy(LineStr, SpacePos + 1, L - SpacePos); // 取常用拼音代码
end;
ImCodes[Ord(LineStr[1]) - 128, Ord(LineStr[2]) - 63].PYCode := PYCode;
end;
end;
result := 1;
finally
CloseFile(SrcFp);
end;
except
end;
end;
function UseInplace: integer;
begin
gi_loaded := 0;
result := 0;
end;
function UseOutplace: integer;
begin
gi_loaded := 1;
result := 1;
end;
function IsOutplace: integer;
begin
result := gi_loaded;
end;
end.
'1','2','3','4','5','6','7','8','9','10','','','','','','',
'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20',
'1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20',
'1','2','3','4','5','6','7','8','9','10','','',
'1','2','3','4','5','6','7','8','9','10','','',
'1','2','3','4','5','6','7','8','9','10','11','12','',''
);
CharIndex2: array [1..24] of string[2] = ( { 希腊字母 }
'a','b','g','d','e','z','e','th','i','k','l','m','n','x','o','p','r',
's','t','u','ph','kh','ps','o'
);
// Pascal -> PChar
// 直接使用 PChar 转化有时会转化出错
function StrPch(const stPas: string): PChar;
begin
// Result := '';
GetMem(Result, Length(stPas) + 1);
StrPCopy(Result, stPas);
end;
function MakeSpellCode(stText: string; iMode, iCount: Integer): string;
var
i, Index: integer;
APy, ls_code: string;
fFlag1, fFlag2, fFlag3: Boolean;
begin
fFlag1 := (iMode and $0001) = 1;
fFlag2 := (iMode and $0002) = 2;
fFlag3 := (iMode and $0004) = 4;
Result := '';
if iMode < 0 then Exit;
i := 1;
while (i <= Length(stText)) do begin
if (Ord(stText[i]) >= 129) and (Ord(stText[i + 1]) >= 64) then begin
// 是否为 GBK 字符
case Ord(stText[i]) of
163: // 全角 ASCII
begin
APy := Chr(Ord(stText[i + 1]) - 128);
// 控制不能输出非数字, 字母的字符
if not fFlag3 and not (APy[1] in ['a'..'z', 'A'..'Z', '0'..'9']) then
APy := '';
end;
162: // 罗马数字
if Ord(stText[i + 1]) > 160 then
APy := CharIndex[Ord(stText[i + 1]) - 160] else
// 在罗马数字区, 不能翻译的字符非罗马数字
if fFlag2 then APy := '?' else APy := '';
166: // 希腊字母
if Ord(stText[i + 1]) in [$A1..$B8] then
APy := UpperCase(CharIndex2[Ord(stText[i + 1]) - $A0])
else if Ord(stText[i + 1]) in [$C1..$D8] then
APy := UpperCase(CharIndex2[Ord(stText[i + 1]) - $C0]);
else // 一般汉字
if gi_loaded = 1 then begin // 使用外挂
// 获得拼音索引
ls_code := IMCodes[Ord(stText[i]) - 128, Ord(stText[i + 1]) - 63].PYCode;
if not fFlag1 then // iFlag1 = False, 是单拼音
APy := Copy(Uppercase(ls_code), 1, 1) else
APy := Copy(Uppercase(ls_code), 1, 6);
end else begin // 使用内置
// 获得拼音索引
Index := PyCodeIndex[Ord(stText[i]) - 128, Ord(stText[i + 1]) - 63];
if Index = 0 then // 无此汉字, 不能翻译的字符, GBK 保留
if fFlag2 then APy := '?' else APy := ''
else if not fFlag1 then // iFlag1 = False, 是单拼音
APy := Copy(Uppercase(PyMusicCode[Index]), 1, 1) else
APy := Copy(Uppercase(PyMusicCode[Index]), 1, 6);
end;
end;
Result := Result + APy;
Inc(i, 2);
end else begin // 在 GBK 字符集外, 即半角字符
if fFlag3 or (stText[i] in ['a'..'z', 'A'..'Z', '0'..'9']) then
Result := Result + UpperCase(stText[i]);
Inc(i);
end;
end;
Result := Copy(Result, 1, iCount);
end;
function GetSpellCode(szText: PChar; iMode, iCount: Integer): PChar;
// Call MakeSpellCode
begin
Result := StrPch(MakeSpellCode(String(szText), iMode, iCount));
end;
function LoadIMCode(as_dict_file: PChar): integer;
// 切换字典
var
SpacePos, L, I, J :Integer;
//index: Integer;
PYCode: string[6];
ls_dict_file, LineStr: string;
SrcFp: TextFile; { 汉字输入法代码字典文件 }
begin
gi_loaded := 1;
ls_dict_file := string(as_dict_file);
result := 0;
for J := 1 to 126 do { 初始化处理 }
for I := 1 to 191 do ImCodes[J, I].PYCode := '';
try
try
AssignFile(SrcFp, ls_dict_file);
Reset(SrcFp);
while not EOF(SrcFp) do begin
ReadLn(SrcFp, LineStr);
if (Ord(LineStr[1]) >= 129) and (Ord(LineStr[2]) >= 64)
{ GBK 内码区间: 首字节: $81 - $FE
尾字节: $40 - $7E, $80 - $FE }
and (LineStr[3] in ['0'..'9', 'A'..'Z', 'a'..'z']) then begin
SpacePos := Pos(' ', LineStr);
if SpacePos = 0 then // 单音字
PYCode := Copy(LineStr, 3, 6) // 取拼音代码
else begin // 多音字
L := Length(LineStr);
PYCode := Copy(LineStr, SpacePos + 1, L - SpacePos); // 取常用拼音代码
end;
ImCodes[Ord(LineStr[1]) - 128, Ord(LineStr[2]) - 63].PYCode := PYCode;
end;
end;
result := 1;
finally
CloseFile(SrcFp);
end;
except
end;
end;
function UseInplace: integer;
begin
gi_loaded := 0;
result := 0;
end;
function UseOutplace: integer;
begin
gi_loaded := 1;
result := 1;
end;
function IsOutplace: integer;
begin
result := gi_loaded;
end;
end.
#5
不行贴不下 呵呵
我发到我的网站上你去下载吧
http://nullspace.cnwindows.com
#6
谢了,马上去看看
#7
以前改过一个DELPHI的代码,很乱,希望有帮助
//---------------------------------------------------------------------------
unsigned char GetPYIndexChar( AnsiString str_test)
{
unsigned char Buffer[2];
unsigned char Return_char = 0 ;
Word In_code = 0x00;
int i;
for ( i = 0 ; i < 2 ; i++ )
{
Buffer[i] = 0x00;
}
unsigned char *p;
p = (unsigned char*)str_test.c_str();
for ( i = 0 ; i < 2 ; i++ )
{
Buffer[i] = (unsigned char)*p ;
p++;
}
Word Left_eight = Word(Buffer[0]) << 8;
Word Right_right = Word(Buffer[1]) ;
In_code = Left_eight + Right_right ;
if ( ( In_code >= 0xB0A1 ) && ( In_code <= 0xB0C4 ) )
{
Return_char = 'A' ;
}
else if ( ( In_code >= 0xB0C5 ) && ( In_code <= 0xB2C0 ) )
{
Return_char = 'B' ;
}
else if ( ( In_code >= 0xB2C1 ) && ( In_code <= 0xB4ED ) )
{
Return_char = 'C' ;
}
else if ( ( In_code >= 0xB4EE ) && ( In_code <= 0xB6E9 ) )
{
Return_char = 'D' ;
}
else if ( ( In_code >= 0xB6EA ) && ( In_code <= 0xB7A1 ) )
{
Return_char = 'E' ;
}
else if ( ( In_code >= 0xB7A2 ) && ( In_code <= 0xB8C0 ) )
{
Return_char = 'F' ;
}
else if ( ( In_code >= 0xB8C1 ) && ( In_code <= 0xB9FD ) )
{
Return_char = 'G' ;
}
else if ( ( In_code >= 0xB9FE ) && ( In_code <= 0xBBF6 ) )
{
Return_char = 'H' ;
}
else if ( ( In_code >= 0xBBF7 ) && ( In_code <= 0xBFA5 ) )
{
Return_char = 'J' ;
}
else if ( ( In_code >= 0xBFA6 ) && ( In_code <= 0xC0AB ) )
{
Return_char = 'K' ;
}
else if ( ( In_code >= 0xC0AC ) && ( In_code <= 0xC2E7 ) )
{
Return_char = 'L' ;
}
else if ( ( In_code >= 0xC2E8 ) && ( In_code <= 0xC4C2 ) )
{
Return_char = 'M' ;
}
else if ( ( In_code >= 0xC4C3 ) && ( In_code <= 0xC5B5 ) )
{
Return_char = 'N' ;
}
else if ( ( In_code >= 0xC5B6 ) && ( In_code <= 0xC5BD ) )
{
Return_char = 'O' ;
}
else if ( ( In_code >= 0xC5BE ) && ( In_code <= 0xC6D9 ) )
{
Return_char = 'P' ;
}
else if ( ( In_code >= 0xC6DA ) && ( In_code <= 0xC8BA ) )
{
Return_char = 'Q' ;
}
else if ( ( In_code >= 0xC8BB ) && ( In_code <= 0xC8F5 ) )
{
Return_char = 'R' ;
}
else if ( ( In_code >= 0xC8F6 ) && ( In_code <= 0xCBF9 ) )
{
Return_char = 'S' ;
}
else if ( ( In_code >= 0xCBFA ) && ( In_code <= 0xCDD9 ) )
{
Return_char = 'T' ;
}
else if ( ( In_code >= 0xCDDA ) && ( In_code <= 0xCEF3 ) )
{
Return_char = 'W' ;
}
else if ( ( In_code >= 0xCEF4 ) && ( In_code <= 0xD188 ) )
{
Return_char = 'X' ;
}
else if ( ( In_code >= 0xD1B9 ) && ( In_code <= 0xD4D0 ) )
{
Return_char = 'Y' ;
}
else if ( ( In_code >= 0xD4D1 ) && ( In_code <= 0xD7F9 ) )
{
Return_char = 'Z' ;
}
else
{
Return_char = 0 ;
}
return Return_char ;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
unsigned char GetPYIndexChar( AnsiString str_test)
{
unsigned char Buffer[2];
unsigned char Return_char = 0 ;
Word In_code = 0x00;
int i;
for ( i = 0 ; i < 2 ; i++ )
{
Buffer[i] = 0x00;
}
unsigned char *p;
p = (unsigned char*)str_test.c_str();
for ( i = 0 ; i < 2 ; i++ )
{
Buffer[i] = (unsigned char)*p ;
p++;
}
Word Left_eight = Word(Buffer[0]) << 8;
Word Right_right = Word(Buffer[1]) ;
In_code = Left_eight + Right_right ;
if ( ( In_code >= 0xB0A1 ) && ( In_code <= 0xB0C4 ) )
{
Return_char = 'A' ;
}
else if ( ( In_code >= 0xB0C5 ) && ( In_code <= 0xB2C0 ) )
{
Return_char = 'B' ;
}
else if ( ( In_code >= 0xB2C1 ) && ( In_code <= 0xB4ED ) )
{
Return_char = 'C' ;
}
else if ( ( In_code >= 0xB4EE ) && ( In_code <= 0xB6E9 ) )
{
Return_char = 'D' ;
}
else if ( ( In_code >= 0xB6EA ) && ( In_code <= 0xB7A1 ) )
{
Return_char = 'E' ;
}
else if ( ( In_code >= 0xB7A2 ) && ( In_code <= 0xB8C0 ) )
{
Return_char = 'F' ;
}
else if ( ( In_code >= 0xB8C1 ) && ( In_code <= 0xB9FD ) )
{
Return_char = 'G' ;
}
else if ( ( In_code >= 0xB9FE ) && ( In_code <= 0xBBF6 ) )
{
Return_char = 'H' ;
}
else if ( ( In_code >= 0xBBF7 ) && ( In_code <= 0xBFA5 ) )
{
Return_char = 'J' ;
}
else if ( ( In_code >= 0xBFA6 ) && ( In_code <= 0xC0AB ) )
{
Return_char = 'K' ;
}
else if ( ( In_code >= 0xC0AC ) && ( In_code <= 0xC2E7 ) )
{
Return_char = 'L' ;
}
else if ( ( In_code >= 0xC2E8 ) && ( In_code <= 0xC4C2 ) )
{
Return_char = 'M' ;
}
else if ( ( In_code >= 0xC4C3 ) && ( In_code <= 0xC5B5 ) )
{
Return_char = 'N' ;
}
else if ( ( In_code >= 0xC5B6 ) && ( In_code <= 0xC5BD ) )
{
Return_char = 'O' ;
}
else if ( ( In_code >= 0xC5BE ) && ( In_code <= 0xC6D9 ) )
{
Return_char = 'P' ;
}
else if ( ( In_code >= 0xC6DA ) && ( In_code <= 0xC8BA ) )
{
Return_char = 'Q' ;
}
else if ( ( In_code >= 0xC8BB ) && ( In_code <= 0xC8F5 ) )
{
Return_char = 'R' ;
}
else if ( ( In_code >= 0xC8F6 ) && ( In_code <= 0xCBF9 ) )
{
Return_char = 'S' ;
}
else if ( ( In_code >= 0xCBFA ) && ( In_code <= 0xCDD9 ) )
{
Return_char = 'T' ;
}
else if ( ( In_code >= 0xCDDA ) && ( In_code <= 0xCEF3 ) )
{
Return_char = 'W' ;
}
else if ( ( In_code >= 0xCEF4 ) && ( In_code <= 0xD188 ) )
{
Return_char = 'X' ;
}
else if ( ( In_code >= 0xD1B9 ) && ( In_code <= 0xD4D0 ) )
{
Return_char = 'Y' ;
}
else if ( ( In_code >= 0xD4D1 ) && ( In_code <= 0xD7F9 ) )
{
Return_char = 'Z' ;
}
else
{
Return_char = 0 ;
}
return Return_char ;
}
//---------------------------------------------------------------------------
#8
续。
AnsiString SearchByPYIndexStr( TStrings *SourceStrs , AnsiString PYIndexStr)
{
int i = 0 ;
int j = 0 ;
AnsiString hzchar = "" ;
bool Find_ok = true ;
AnsiString result = "" ;
unsigned char *p_hzchar;
p_hzchar = PYIndexStr.c_str();
if ( p_hzchar[0] <= 127 )
{
for ( i = 0 ; i <= SourceStrs->Count - 1 ; i++ )
{
Find_ok = true ;
AnsiString str_hang = "" ;
for ( j = 0 ; j < PYIndexStr.Length() ; j++ )
{
str_hang = SourceStrs->Strings[i];
hzchar = str_hang.SubString( 2 * j + 1 , 2 );
AnsiString str_temp = "";
str_temp = AnsiString(char(p_hzchar[j]));
if (( str_hang.SubString( j + 1 , 1 ).UpperCase() != PYIndexStr.SubString( j + 1 , 1 ).UpperCase()) && (p_hzchar[j] != '?')&& (str_temp.UpperCase() != AnsiString(char(GetPYIndexChar(hzchar)))))
{
Find_ok = false ;
break;
}
}
if ( Find_ok == true )
{
if ( result == "" )
{
result = SourceStrs->Strings[i];
}
else
{
result = result + char(13) + SourceStrs->Strings[i];
}
}
}
}
else
{
for ( i = 0 ; i <= SourceStrs->Count - 1 ; i++ )
{
Find_ok = true ;
for ( j = 0 ; j < PYIndexStr.Length() / 2 ; j++ )
{
if ( SourceStrs->Strings[i].SubString( 2 * j + 1 , 2 ) != PYIndexStr.SubString( 2 * j + 1 , 2 ) )
{
Find_ok = false ;
break;
}
}
if ( Find_ok == true )
{
if ( result == "" )
{
result = SourceStrs->Strings[i];
}
else
{
result = result + char(13) + SourceStrs->Strings[i];
}
}
}
}
return result ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
if ( SearchByPYIndexStr(ListBox1->Items , Edit1->Text) != "" )
{
ListBox2->Visible = true ;
ListBox2->Items->Text = SearchByPYIndexStr(ListBox1->Items , Edit1->Text) ;
}
else
{
ListBox2->Visible = false ;
}
if ( Edit1->Text == "" )
{
ListBox2->Visible = false ;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ( Key == VK_DOWN && ListBox2->Visible == true )
{
ListBox2->SetFocus();
ListBox2->Selected[0];
ListBox2->Focused();
ListBox2->CanFocus();
ListBox2->Refresh();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox2KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ( Key == VK_BACK || Key == VK_ESCAPE)
{
Edit1->SetFocus();
Edit1->SelStart = Edit1->Text.Length();
}
if ( Key == VK_RETURN )
{
Label1->Caption = ListBox2->Items->Strings[ListBox2->ItemIndex];
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ListBox1->Items->Add("你好") ;
ListBox1->Items->Add("你好吗") ;
ListBox1->Items->Add("谢谢你") ;
ListBox1->Items->Add("谢你") ;
ListBox1->Items->Add("谢谢") ;
ListBox1->Items->Add("aaaa") ;
}
//---------------------------------------------------------------------------
//注:对于生僻字不能查找
AnsiString SearchByPYIndexStr( TStrings *SourceStrs , AnsiString PYIndexStr)
{
int i = 0 ;
int j = 0 ;
AnsiString hzchar = "" ;
bool Find_ok = true ;
AnsiString result = "" ;
unsigned char *p_hzchar;
p_hzchar = PYIndexStr.c_str();
if ( p_hzchar[0] <= 127 )
{
for ( i = 0 ; i <= SourceStrs->Count - 1 ; i++ )
{
Find_ok = true ;
AnsiString str_hang = "" ;
for ( j = 0 ; j < PYIndexStr.Length() ; j++ )
{
str_hang = SourceStrs->Strings[i];
hzchar = str_hang.SubString( 2 * j + 1 , 2 );
AnsiString str_temp = "";
str_temp = AnsiString(char(p_hzchar[j]));
if (( str_hang.SubString( j + 1 , 1 ).UpperCase() != PYIndexStr.SubString( j + 1 , 1 ).UpperCase()) && (p_hzchar[j] != '?')&& (str_temp.UpperCase() != AnsiString(char(GetPYIndexChar(hzchar)))))
{
Find_ok = false ;
break;
}
}
if ( Find_ok == true )
{
if ( result == "" )
{
result = SourceStrs->Strings[i];
}
else
{
result = result + char(13) + SourceStrs->Strings[i];
}
}
}
}
else
{
for ( i = 0 ; i <= SourceStrs->Count - 1 ; i++ )
{
Find_ok = true ;
for ( j = 0 ; j < PYIndexStr.Length() / 2 ; j++ )
{
if ( SourceStrs->Strings[i].SubString( 2 * j + 1 , 2 ) != PYIndexStr.SubString( 2 * j + 1 , 2 ) )
{
Find_ok = false ;
break;
}
}
if ( Find_ok == true )
{
if ( result == "" )
{
result = SourceStrs->Strings[i];
}
else
{
result = result + char(13) + SourceStrs->Strings[i];
}
}
}
}
return result ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
if ( SearchByPYIndexStr(ListBox1->Items , Edit1->Text) != "" )
{
ListBox2->Visible = true ;
ListBox2->Items->Text = SearchByPYIndexStr(ListBox1->Items , Edit1->Text) ;
}
else
{
ListBox2->Visible = false ;
}
if ( Edit1->Text == "" )
{
ListBox2->Visible = false ;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ( Key == VK_DOWN && ListBox2->Visible == true )
{
ListBox2->SetFocus();
ListBox2->Selected[0];
ListBox2->Focused();
ListBox2->CanFocus();
ListBox2->Refresh();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox2KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if ( Key == VK_BACK || Key == VK_ESCAPE)
{
Edit1->SetFocus();
Edit1->SelStart = Edit1->Text.Length();
}
if ( Key == VK_RETURN )
{
Label1->Caption = ListBox2->Items->Strings[ListBox2->ItemIndex];
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ListBox1->Items->Add("你好") ;
ListBox1->Items->Add("你好吗") ;
ListBox1->Items->Add("谢谢你") ;
ListBox1->Items->Add("谢你") ;
ListBox1->Items->Add("谢谢") ;
ListBox1->Items->Add("aaaa") ;
}
//---------------------------------------------------------------------------
//注:对于生僻字不能查找
#9
以上是输入拼音查汉字
#10
好啊,我试试
#11
我UP
#12
里面有头文件,OBJ文件呀 include就可以调用了
如:
GetSpellCode(Edit2->Text.c_str(),0,StrLen(Edit2->Text.c_str()));
#13
呵呵!阿星!哪裏找的?
#14
原来是蠱惑兄呀
呵我的收藏
在我的网站
http://nullspace.cnwindows.com可以下
#15
“如何加已有的OBJ文件?”
执行菜单命令[Project]/[Add to Project],然后选择要加的 obj 文件就可以了。
执行菜单命令[Project]/[Add to Project],然后选择要加的 obj 文件就可以了。
#16
关注