我也是摘录的:
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: Integer;
begin
Result := '';
for I := 1 to Length(Source) do
begin
S1 := ord(Source[i]);
if ((S1>=Low(ASCII)) and (S1<=High(ASCII))) then
begin
Result := Result + Alpha[S1];
end;
end;
end;
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: Integer;
begin
Result := '';
for I := 1 to Length(Source) do
begin
S1 := ord(Source[i]);
if ((S1>=Low(ASCII)) and (S1<=High(ASCII))) then
begin
Result := Result + Alpha[S1];
end;
end;
end;
http://www.codelphi.com/channel/hjwz/read.asp?ano=807
先注册,再登陆
http://kingron.myetang.com/zsfunc02.htm(*//
标题:对全角半角字符串的处理
说明:使用于运用程序中避免用户输入字符不统一
设计:Zswang
日期:2002-01-24
支持:[email protected]
//*)///////Begin Source
const
cCharCn: array[#32 .. #126] of string[2] =
(
{ }' ',{!}'!',{"}'"',{#}'#',{ }'$',{%}'%',{&}'&',{'}''',{(}'(',
{)}')',{*}'*',{+}'+',{,}',',{-}'-',{.}'。',{/}'/',{0}'0',{1}'1',
{2}'2',{3}'3',{4}'4',{5}'5',{6}'6',{7}'7',{8}'8',{9}'9',{:}':',
{;}';',{<}'<',{=}'=',{>}'>',{?}'?',{@}'@',{A}'A',{B}'B',{C}'C',
{D}'D',{E}'E',{F}'F',{G}'G',{H}'H',{I}'I',{J}'J',{K}'K',{L}'L',
{M}'M',{N}'N',{O}'O',{P}'P',{Q}'Q',{R}'R',{S}'S',{T}'T',{U}'U',
{V}'V',{W}'W',{X}'X',{Y}'Y',{Z}'Z',{[}'[',{\}'\',{]}']',{^}'^',
{_}'_',{`}'`',{a}'a',{b}'b',{c}'c',{d}'d',{e}'e',{f}'f',{g}'g',
{h}'h',{i}'i',{j}'j',{k}'k',{l}'l',{m}'m',{n}'n',{o}'o',{p}'p',
{q}'q',{r}'r',{s}'s',{t}'t',{u}'u',{v}'v',{w}'w',{x}'x',{y}'y',
{z}'z',{{}'{',{|}'|',{ }'}',{~}'~');function StrToGBText(mStr: string): string; { 返回字符串转换成全角字符串 }
var
I: Integer;
begin
Result := '';
for I := 1 to Length(mStr) do
case mStr[I] of
#32 .. #126: Result := Result + cCharCn[mStr[I]];
else Result := Result + mStr[I];
end;
end; { StrToGBText }function GBTextToStr(mText: string): string; { 返回字符串转换成半角字符串 }
var
I: Integer;
J: Char;
S: string;
begin
Result := '';
for I := 1 to Length(WideString(mText)) do begin
S := WideString(mText)[I];
if Length(S) > 1 then for J := #32 to #126 do
if cCharCn[J] = S then begin
S := J;
Break;
end;
Result := Result + S;
end;
end; { GBTextToStr }
///////End Source///////Begin Demo
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Text := StrToGBText(Memo2.Text);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Memo2.Text := GBTextToStr(Memo1.Text);
end;
///////End Demo