Unicode

xiaoxiao2021-03-06  61

Unit unit1;

Interface

Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;

type TForm1 = class (TForm) Button1: TButton; procedure Button1Click (Sender: TObject); private function AnsiToUnicode (Ansi: string): string; function UnicodeToAnsi (Unicode: string): string; function ReadHex (AString: string): integer; {Private declarations}} {public declarations} END;

Var Form1: TFORM1;

IMPLEMENTATION

{$ R * .dfm}

Function TForm1.ansitounicode (ANSI: STRING): String;

VAR

String;

i: integer;

J, K: String [2];

A: array [1..1000] of char;

Begin

s: = '';

Stringtowidechar (ANSI, @ (a [1]), 500);

I: = 1;

While ((a [i] <> # 0) or (a [i 1] <> # 0)) DO Begin

J: = INTTOHEX (Integer (A [i]), 2);

K: = INTTOHEX (Integer (A [i 1]), 2);

S: = S K J;

I: = i 2;

END;

Result: = S;

End; Function TFORM1.Readhex (Astring: String): Integer;

Begin

Result: = STRTOINT ('$' astring)

END;

Function TFORM1.UNICODETOANSI (Unicode: String): String;

VAR

String;

i: integer;

J, K: String [2];

Begin

I: = 1;

s: = '';

While I

J: = COPY (Unicode, i 2, 2);

K: = Copy (Unicode, I, 2);

i: = i 4;

S: = s char (Readhex (j)) char (Readhex (k));

END;

IF s <> '' THEN

S: = WideChartostring (PWIDECHAR (S # 0 # 0 # 0 # 0)))))

Else

s: = '';

Result: = S;

END;

Procedure TForm1.Button1Click (Sender: TOBJECT); Begin ShowMessage (Ansitounicode ('we')); showMessage ('62114eec');

End.

转载请注明原文地址:https://www.9cbs.com/read-112311.html

New Post(0)