这是一个取汉字拼音首字母的函数,但不知为什么一碰到"陈登华文选集"这几个汉字就死循环,帮我看看错误出在那里,谢谢!下面是这个函数!function ChineseToSpell(Chinese: string): string;
function GetPYIndexChar(hzchar: string): Char;
begin
case Word(hzchar[1]) shl 8 + Word(hzchar[2]) of
$B0A1..$B0C4: Result := 'a';
$B0C5..$B2C0: Result := 'b';
$B2C1..$B4ED: Result := 'c';
$B4EE..$B6E9: Result := 'd';
$B6EA..$B7A1: Result := 'e';
$B7A2..$B8C0: Result := 'f';
$B8C1..$B9FD: Result := 'g';
$B9FE..$BBF6: Result := 'h';
$BBF7..$BFA5: Result := 'j';
$BFA6..$C0AB: Result := 'k';
$C0AC..$C2E7: Result := 'l';
$C2E8..$C4C2: Result := 'm';
$C4C3..$C5B5: Result := 'n';
$C5B6..$C5BD: Result := 'o';
$C5BE..$C6D9: Result := 'p';
$C6DA..$C8BA: Result := 'q';
$C8BB..$C8F5: Result := 'r';
$C8F6..$CBF9: Result := 's';
$CBFA..$CDD9: Result := 't';
$CDDA..$CEF3: Result := 'w';
$CEF4..$D188: Result := 'x';
$D1B9..$D4D0: Result := 'y';
$D4D1..$D7F9: Result := 'z';
else
Result := Char(32);
end;
end;
var
i : Integer;
C : Char;
Spell: string;
begin
Spell := '';
i := 1;
while i <= Length(Chinese) do
begin
if Chinese[i] <= Chr(127) then
begin
Spell := Spell + UpCase(Chinese[i]);
i := i + 1;
end
else
begin
C := GetPYIndexChar(Copy(Chinese, i, 2));
if C <> Char(32) then
begin
Spell := Spell + UpCase(C);
i := i + 2;
end;
end;
end;
Result := Spell;
end;
这是调用这个函数:
procedure TForm1.Button1Click(Sender: TObject);
var
Spell : string;
begin
Spell := ChineseToSpell('陈登华文选集');
end;
function GetPYIndexChar(hzchar: string): Char;
begin
case Word(hzchar[1]) shl 8 + Word(hzchar[2]) of
$B0A1..$B0C4: Result := 'a';
$B0C5..$B2C0: Result := 'b';
$B2C1..$B4ED: Result := 'c';
$B4EE..$B6E9: Result := 'd';
$B6EA..$B7A1: Result := 'e';
$B7A2..$B8C0: Result := 'f';
$B8C1..$B9FD: Result := 'g';
$B9FE..$BBF6: Result := 'h';
$BBF7..$BFA5: Result := 'j';
$BFA6..$C0AB: Result := 'k';
$C0AC..$C2E7: Result := 'l';
$C2E8..$C4C2: Result := 'm';
$C4C3..$C5B5: Result := 'n';
$C5B6..$C5BD: Result := 'o';
$C5BE..$C6D9: Result := 'p';
$C6DA..$C8BA: Result := 'q';
$C8BB..$C8F5: Result := 'r';
$C8F6..$CBF9: Result := 's';
$CBFA..$CDD9: Result := 't';
$CDDA..$CEF3: Result := 'w';
$CEF4..$D188: Result := 'x';
$D1B9..$D4D0: Result := 'y';
$D4D1..$D7F9: Result := 'z';
else
Result := Char(32);
end;
end;
var
i : Integer;
C : Char;
Spell: string;
begin
Spell := '';
i := 1;
while i <= Length(Chinese) do
begin
if Chinese[i] <= Chr(127) then
begin
Spell := Spell + UpCase(Chinese[i]);
i := i + 1;
end
else
begin
C := GetPYIndexChar(Copy(Chinese, i, 2));
if C <> Char(32) then
begin
Spell := Spell + UpCase(C);
i := i + 2;
end;
end;
end;
Result := Spell;
end;
这是调用这个函数:
procedure TForm1.Button1Click(Sender: TObject);
var
Spell : string;
begin
Spell := ChineseToSpell('陈登华文选集');
end;
解决方案 »
- CommPortDriver第三方控件安装问题
- 问个傻傻的存储过程问题
- 这是怎么回事啊?高手请进[悬赏100分]
- 我有个问题,在线等.朋友都进来吧!!!不怎么难.
- 如何把一个string的内容作为一个控件名,去操作或者设置控件的属性?
- 求救求救!
- 一个关于winsocket的问题,怪怪的。各位大虾请多关注。csdn最近太慢了,好像人上来也少了。
- 做报表时请问怎样才能让QRDBText里的内容自动折行啊(因为内容有点长,如果不折行很难看)?我设置了height和width还是不行啊,
- 求各位高人帮忙。先行谢过!
- 我要实践????????????????
- 大家快进所有分都送很简单的(在线等)
- 大家好,请帮我看看这个函数,看毛病出在那里!(这是个很实用的函数,可能对大家有点用!)
1.想要大写改成大写字母好了:
function GetEn(CnString: string): string;
function GetEnChar(cnchar: string): char;
begin
case Word(cnchar[1]) shl 8 + Word(cnchar[2]) of
$B0A1..$B0C4: result := 'a';
$B0C5..$B2C0: result := 'b';
$B2C1..$B4ED: result := 'c';
$B4EE..$B6E9: result := 'd';
$B6EA..$B7A1: result := 'e';
$B7A2..$B8C0: result := 'f';
$B8C1..$B9FD: result := 'g';
$B9FE..$BBF6: result := 'h';
$BBF7..$BFA5: result := 'j';
$BFA6..$C0AB: result := 'k';
$C0AC..$C2E7: result := 'l';
$C2E8..$C4C2: result := 'm';
$C4C3..$C5B5: result := 'n';
$C5B6..$C5BD: result := 'o';
$C5BE..$C6D9: result := 'p';
$C6DA..$C8BA: result := 'q';
$C8BB..$C8F5: result := 'r';
$C8F6..$CBF9: result := 's';
$CBFA..$CDD9: result := 't';
$CDDA..$CEF3: result := 'w';
$CEF4..$D188: result := 'x';
$D1B9..$D4D0: result := 'y';
$D4D1..$D7F9: result := 'z';
else
result := char(0);
end;
end;
var
i, len: integer;
begin
CnString := StringReplace(CnString, ' ', '', [rfReplaceAll]); //删除空格
len := Length(CnString) - Length(WideString(CnString)); //汉字个数
for i := 1 to len do
result := result + GetEnChar(copy(CnString, 2*i-1, 2));
end;
C := GetPYIndexChar(Copy(Chinese, i, 2));
if C <> Char(32) then {在这里;若不成立,下面的i := i + 2执行不到,成死循环}
begin
Spell := Spell + UpCase(C);
i := i + 2;
end;
要改成
C := GetPYIndexChar(Copy(Chinese, i, 2));
if C <> Char(32) then
Spell := Spell + UpCase(C);
i := i + 2;