把string强制转成widestring的时候,当string里面的数据不巧为一些特殊数据时,widestring会把它转换成其他字符,造成数据丢失,请问怎么解决?var S:string;
WS:widestring;
begin
s:=#2+#3+#0+#10+#0+#1+#164+#59;
showmessage(inttostr(Length(S)));
WS:=widestring(S);
S:=WS;
showmessage(inttostr(Length(S)));
end;第一个得出的长度是8
第二个得出的长度就变成7了
请问怎么才能使数据不丢失?
做项目的时候,widestring是接口,但是由于处理的数据都是16进制的,所以我在内部都转成string或者array of byte,最后的时候才转换一下。。没想到还是出这种问题..
WS:widestring;
begin
s:=#2+#3+#0+#10+#0+#1+#164+#59;
showmessage(inttostr(Length(S)));
WS:=widestring(S);
S:=WS;
showmessage(inttostr(Length(S)));
end;第一个得出的长度是8
第二个得出的长度就变成7了
请问怎么才能使数据不丢失?
做项目的时候,widestring是接口,但是由于处理的数据都是16进制的,所以我在内部都转成string或者array of byte,最后的时候才转换一下。。没想到还是出这种问题..
解决方案 »
- 我用了pcsc读卡器。怎么选择读卡器中psam卡和用户卡。高手请进-------------
- 小弟,在这里向各位大哥帮帮忙吗,这个问题10天了还是没有搞定,没有分了,请谅解,谢谢!
- 请教如何制作安装包?
- 如何从字符串中提取单词?
- 100分求自定义组件的属性编辑器的源代码
- 问个简单的问题:那位兄弟看过(delphi5.x分布式多层应用电子商务篇),今天刚看第二章第一个例题,编译成DLL后,用IE打开它怎么也显示不
- 我需要检测一个同目录的文件是否存在,然后再决定是否执行某种动作,这样的代码怎么写?
- 請問有誰知道用API函數發E-mail時,如何直接加入一附件后E到指定郵箱呢?
- 请大家多捧场
- 找人
- 我用ACCESS,想使字段名按列显示,而记录则按行显示 ???怎么写SQL语句
- 我在VB中调用的一个汉字转拼音DLL,怎么在DELPHI中调用这个?
因为#164>#128,所以转换到#164时它判断在A0~FE,所以它认为下个字符应该是在40~FE,
但它发现它是#59不符合编码规则便把#164转化为ANSI#63.
你试着:
s:=#2+#3+#0+#10+#0+#1+#164+#64
s:=#2+#3+#0+#10+#0+#1+#236+#164+#59;
GBK编码
其第一字节的值在 16 进制的 81~FE 之间,第二字节在 40~FE
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementation{$R *.dfm}var len:integer;function GetWideString(Const s:string):WideString;
var i:integer;
u4str:UCS4String;
begin
len:=Length(S);
SetLength(u4str,len+1);
for i:=1 to len do
begin
u4str[i-1]:=UCS4Char(S[i]);
end;
u4str[len]:= UCS4Char(#0);
Result:=UCS4StringToWideString(u4str);
end;function GetString(Const WideStr:WideString):String;
var u4str:UCS4String;
i:integer;
s:string;
begin
setlength(u4str,len+1);
SetLength(s,len);
u4str:=WideStringToUCS4String(WideStr);
for i:=1 to len do
begin
s[i]:=char(u4str[i-1]);
end;
Result:=s;
end;procedure TForm1.Button1Click(Sender: TObject);
var StrInput:string;
StrOutput:string;
WideStr:widestring;
begin
StrInput:=#2+#3+#0+#10+#0+#1+#164+#59; WideStr:= GetWideString(StrInput); //转为widestring StrOutput:=GetString(WideStr); //转为string if StrInput=StrOutput then
showmessage('ok');
end;end.
我想先知道楼主信誉为何如此之低他的贴子是都结了啊,奇怪了
老实说我也不知道帖子都结掉的啊~~
诚实,呵呵,是CSDN管理出问题了吗
老实说本来一个字节的东东,先拉长成4个字节,再缩小到2个字节。。看上去真的很不爽啊。。
I: Integer;
WS:widestring;
begin
s:=#2+#3+#0+#10+#0+#1+#164+#59;
// showmessage(inttostr(Length(S)));
setlength(WS,Length(S));
for I := 1 to length(S) do // Iterate
begin
WS[I]:= widechar(S[I]);
end; // for showmessage(inttostr(Length(WS))); setlength(S2,Length(WS));
for I := 1 to length(S) do // Iterate
begin
S2[I]:= char(WS[I]);
end; // for
showmessage(inttostr(Length(S2))); if S=S2 then showmessage('OK');