delphi2007中怎样把这段字符转化为中文
现有编码一串 例如:论坛 现在已知它对应的中文应该是“论坛”。我想知道在delphi2007中是用什么函数转换的,最好能有个例子就再好不过了。
[解决办法]
用Chr()函数就可以了,例如:
ShowMessage(Chr(35770)+Chr(22363));
Chr()函数需要提供的是字符的编号,即数字,所以,需要把&#号去掉。
[解决办法]
不知道D2007是否跟D7一样,D7下我帮你写了个最笨的,呵呵,看看其他人有没有更好的转换方法。
uses StrUtils;procedure TForm1.Button2Click(Sender: TObject);var s,s1: string; i: integer; b: array of byte;begin s := '论坛'; //确定字符个数 s1 := s; i := 0; while s1<>'' do begin Inc(i); if Pos(';',s1)>0 then begin Delete(s1,1,Pos(';',s1)); continue; end; s1 := ''; end; SetLength(b,i*2+2); //写入内存 i := 0; while s<>'' do begin if Pos(';',s)>0 then begin s1 := LeftBStr(s,Pos(';',s)-1); Delete(s,1,Pos(';',s)); Delete(s1,1,2); end else begin s1 := s; s:=''; Delete(s1,1,2); end; b[i] := StrToInt(s1) mod 256; b[i+1] := StrToInt(s1) div 256; i := i+2; end; b[i] := 0; b[i+1] := 0; s := WideCharToString(PWideChar(b)); showmessage(s);end;