2010年3月31日 星期三

關於全型轉半形

全型轉半形Function
Function1

function AlphaToAscii(Source: WideString): String;
var
Alpha : WideString;
Ascii : string;
s1 : string;
I, J: Integer;
begin
Result := '';
Alpha := '-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ{\}︿─abcdefghijklmnopqrstuvwxyz';
ASCII := '-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^-abcdefghijklmnopqrstuvwxyz';
for I := 1 to Length(Source) do
begin
S1 := copy(Source,i,1);
J := pos(S1, Alpha );
if J > 0 then
begin
Result := Result + copy(ASCII,J,1);
end;
end;
end;

另一個全部全形轉半形方式

function TfmImport1.textchange(tt:String):String;
var
Chr : array [0..255] of char;
begin
Windows.LCMapString(GetUserDefaultLCID(),LCMAP_HALFWIDTH,PChar(tt),Length(tt)+ 1,chr,Sizeof(chr));
Result := Chr;
end;

沒有留言: