关于unicode转utf-8,该怎么处理
关于unicode转utf-8我的unicode代码另外一种方法在万一老师博客看到function Unicode_str(text: string):s
关于unicode转utf-8
我的unicode代码
另外一种方法
在万一老师博客看到
function Unicode_str(text: string):string;
var
i,len: Integer;
ws: WideString;
begin
ws := '';
i := 1;
len := Length(text);
while i < len do
begin
ws := ws + Widechar(StrToInt('$' + Copy(text,i,4)));
i := i+4;
end;
Result := ws;
end;
但是这种不能解\u的。而且并没有区分英文字符,和半角标点。 Unicode UTF-8 JavaScript
[解决办法]帮你写一个吧,也没几行代码.
const
v = '\u8bf7\u52ff\u62cd\u6444!!\u5076\u50cf\u5185\u5e55 1280x720.EP01.\u6df1\u591c\u5267\u30d0\u30fc.\u5b57\u5e55\u7ec4.mkv';
function UnicodeDecode(const value: Widestring): WideString;
var
P: PWideChar;
v: WideChar;
tmp : Widestring;
begin
P := PChar(value);
while P^ <> #0 do
begin
v := #0;
case P^ of
'\':
begin
Inc(P);
case P^ of
'\':
v := '\';
'u':
begin
tmp := Copy(p,2,4);
v := WideChar(StrToInt('$' + tmp));
Inc(p, 4);
end;
end;
end;
else
V := P^;
end;
Result := Result + v;
Inc(P);
end;
end;
procedure TForm10.Button1Click(Sender: TObject);
begin
Caption := UnicodeDecode(v);
end;