const
cCharCn: array [#32 .. #126] of string[2] = (
' ', '!', '"', '#', '$', '%', '&', ''', '(',
')', '*', '+', ',', '-', '。', '/', '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', '{', '|', '}', '~');
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;
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;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Text := StrToGBText(Memo2.Text);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo2.Text := GBTextToStr(Memo1.Text);
end;