全角转半角


function SbctoDbc(s: string): string;
var
nlength, i: integer;
str, ctmp, c1, c2: string;
begin
nlength := length(s);
if (nlength = 0) then
exit;
str := '';
setlength(ctmp, nlength + 1);
ctmp := s;
i := 1;
while (i <= nlength) do
begin
c1 := ctmp[i];
c2 := ctmp[i + 1];
if (c1 = #163) then
begin
str := str + chr(ord(c2[1]) - 128);
inc(i, 2);
continue;
end;
if (c1 > #163) then
begin
str := str + c1;
str := str + c2;
inc(i, 2);
continue;
end;
if (c1 = #161) and (c2 = #161) then
begin
str := str + ' ';
inc(i, 2);
continue;
end;
str := str + c1;
inc(i);
end;
result := str;
end;

posted @ 2021-05-06 10:09  绿水青山777  阅读(60)  评论(0编辑  收藏  举报