String with nulls inside

Discussion and questions about programming with Ultibo.
msx80
Posts: 32
Joined: Thu Aug 02, 2018 8:38 am

String with nulls inside

Postby msx80 » Sun Dec 02, 2018 2:34 pm

Hi there, a quick freepascal question: i have a buffer with some data (including zeroes). Is there a way i can make it into a regular ansistring?
I know i can get a string from a pchar with strpas or simply casting, but this buffer possibly have zeroes inside and i can't find a function to do that.
I've tryed using setLength and then copy the memory but gives error..
pjde
Posts: 425
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: String with nulls inside

Postby pjde » Sun Dec 02, 2018 8:54 pm

I regularly do something similar
If you have buff as a pointer and bufflen as the length of data and s as the string


SetLength (s, bufflen);
System.Move (buff^, s[1], bufflen);

Regards

Paul
msx80
Posts: 32
Joined: Thu Aug 02, 2018 8:38 am

Re: String with nulls inside

Postby msx80 » Fri Dec 07, 2018 10:44 am

Thanks, in the meantime i also found setStringthat does exacly what i needed :P

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests