混雜半型全型的字串該如何全部轉換成全型字?? |
答題得分者是:shunchia63
|
danice1068
一般會員 發表:3 回覆:1 積分:0 註冊:2006-08-11 發送簡訊給我 |
以下程式是我參考站內半型轉全型問題答覆所寫的
但是我想將地址的字串轉全都轉成全型字 ex: 台北市信義區基隆路2段171-3號5樓A → 台北市信義區基隆路2段171-3號5樓A 程式中傳入字串值該如何判斷是全型還是半型字??或者有什麼更好的方式?? 請各位大大幫忙orz function AsciiToAlpha(Source: String): String; const Alpha: array[45..122] of String = ('-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',':', ';', '<', '=', '>', '?', '', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '\', '}', '︿', '─', '', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v','w','x','y','z'); ASCII: array[45..122] of String = ('-', '.', '/', '0', '1','2', '3', '4', '5', '6','7', '8', '9', ':', ';','<', '=', '>', '?', #0,'A', 'B', 'C', 'D', 'E','F', 'G', 'H', 'I', 'J','K', 'L', 'M', 'N', 'O','P', 'Q', 'R', 'S', 'T','U', 'V', 'W', 'X', 'Y','Z', '[', '\', ']', '^','-', #0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x','y','z'); var I, S1, aa : Integer; str,trans,ansstr : String; Query : TQuery; begin Result := ''; str := ''; trans := ''; ansstr := ''; showmessage(Source); i:=1; while i<= Length(Source) do begin str := ''; str := Copy(Source,i,2); if str > #128 then ansstr := ansstr str else begin str := ''; str := Copy(Source,i,1); S1 := ord(str[i]); if ((S1>=Low(ASCII)) and (S1<=High(ASCII))) then begin trans := ''; trans := Alpha[S1]; ansstr := ansstr trans ; end; str := ''; str := Copy(Source,i 1,1); S1 := ord(str[i 1]); if ((S1>=Low(ASCII)) and (S1<=High(ASCII))) then begin trans := ''; trans := Alpha[S1]; ansstr := ansstr trans ; end; end; showmessage(ansstr); i := i 2; end; showmessage(ansstr); Result := ansstr; end;
------
Brazy |
shunchia63
高階會員 發表:26 回覆:141 積分:198 註冊:2007-05-22 發送簡訊給我 |
[code delphi] function AsciiToAlpha(Source: String): String; const Alpha: array[32..126] of String = ( ' ', '!', '”','#' ,'$' ,'%','&' ,'’' ,'(' ,')','*','+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6','7', '8', '9', ':', ';', '<', '=', '>', '?', '@' , 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '〔', '\', '〕', '︿','_', '’', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h','i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v','w','x','y','z', '{', '|', '}', '~' ); ASCII: array[32..126] of String = ( ' ', '!', '"','#' ,'$' ,'%','&' ,'`' ,'(' ,')','*',' ', ',', '-', '.', '/', '0', '1','2', '3', '4', '5', '6','7', '8', '9', ':', ';','<', '=', '>', '?', '@','A', 'B', 'C', 'D', 'E','F', 'G', 'H', 'I', 'J','K', 'L', 'M', 'N', 'O','P', 'Q', 'R', 'S', 'T','U', 'V', 'W', 'X', 'Y','Z', '[', '\', ']', '^','_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x','y','z', '{', '|', '}', '~' ); var w:WideString; ret:WideString; i:integer; begin w:= Source; i:=1; ret := ''; for i := 1 to length(w) do begin if w[i] >#128 then begin ret := ret w[i]; end else begin if ((ord(w[i]) >=(32)) and (ord(w[i])<=(126))) then begin ret := ret Alpha[ ord(w[i]) ]; end; end; end; result := ret; end; [/code] |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |