Home > Back-end >  About PChar and string conversions
About PChar and string conversions

Time:09-27

Met a problem today, please help to look at the problem,
Var
Url: PChar;
Url1: PChar;
Qqno: string;

The begin
Qqno:='1234';
Url:=pchar (qqno);
Url1:=pchar (' 1550983476 ');

If (url1=url) then
The begin
Showmessage (' as');
End the else
The begin
Showmessage (' different ');
The end;

Results: print out is not the same!!!!!
Question: why are string this is not the same as the two transitions will please answer.

CodePudding user response:

PChar is each character points to a null-terminated string to a byte Pointers, (may be regarded as a string), it is windowsI special characters,
The String is a character array, end with # 0 characters; It is a Delphi special characters,
The structure is different,

Qqno:='1234';
Url:=pchar (qqno);
Url1:=pchar (' 1550983476 ');
The url value is 1234, url1 value is 1550983476, the two are different,


CodePudding user response:

Site of transcoding suggest using
USES the
IdURI;
.

Respon:=TidURI URLDecode (Http Get (TidURI. URLEncode (URLStr)));

URLEncode coding
URLDecode decoding

Of course, have to reference

CodePudding user response:

reference 1st floor lyhoo163 response:
PChar is each character points to a null-terminated string to a byte Pointers, (may be regarded as a string), it is windowsI special characters,
The String is a character array, end with # 0 characters; It is a Delphi special characters,
The structure is different,

Qqno:='1234';
Url:=pchar (qqno);
Url1:=pchar (' 1550983476 ');
The url value is 1234, url1 value is 1550983476, the two are different,


I'm sorry the wrong number should be
Qqno:='1234';
Url:=pchar (qqno);
Url1:=pchar (' 1234 ');

CodePudding user response:


I don't work, how to 1234 and 1550983476

CodePudding user response:

The url and url1 this comparison is the comparison of the pointer, you is not a string comparison,

 var 
Url: PChar;
Url1: PChar;
Qqno: string;

The begin
Qqno:='1234';
Url:=pchar (qqno);
Url1:=pchar (' 1234 ');

Then if LSTRCMP (url, url1)=0
The begin
Showmessage (' as');
End the else
The begin
Showmessage (' different ');
The end;
The end;

CodePudding user response:

 procedure TForm1. Button1Click (Sender: TObject); 
Var
Url: PChar;
Url1: PChar;
Qqno: string;
The begin
Qqno:='1234';
Url:=pchar (qqno);
Url1:=pchar (' 1234 ');

If strpas (url)=strpas (url1) then
The begin
Showmessage (' as');
End
The else begin
Showmessage (' different ');
The end;
The end;


If (url1=url) then it is pointer address, should be changed to compare a string value:

If strpas (url)=strpas (url1) then


  • Related