其他分享
首页 > 其他分享> > 全角转半角

全角转半角

作者:互联网


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;

标签:begin,end,全角,半角,str,c2,c1,ctmp
来源: https://www.cnblogs.com/maweiwei/p/14734021.html