Search a buffer for a string

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

I have a buffer that contains nulls and strings, how can i search it for some strings like i would do with the string functions?

is there any way to dump the buffer to a string and use the string functions?, without writing the buffer to a file and read it to a string.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

why don't you replace all the zeroes for chr(10) and then use FindString()?

Just a suggestion, bye,

El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.
I have a buffer that contains nulls and strings, how can i search it for some strings like i would do with the string functions?

is there any way to dump the buffer to a string and use the string functions?, without writing the buffer to a file and read it to a string.

Why not try the CompareMemoryString() command?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

I haven't tried to replace the nulls, but i think it should be slow to peek every byte and replace it if is a null(if this is the way to do it)

i can't find any help in the Comparememorystring.

i do this to dump the buffer into a string, and don't know if it is correct:

buffer=allocatememory(0,50000,0)
start=buffer
tot.s="" ;string to hold the buffer

Repeat
st.s=PeekS(start)
len=MemoryStringLength(start)+1
start=start+len
tot=tot+st
Until start=buffer+50000

thanks for your help.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

I once wrote a little snippet that searched for a string in memory and then replaced this with another one, you can find this on the PB resource site http://www.reelmediaproductions.com/pb/ it's named 'findandreplacemem'. Removing the replace part from the code shouldn't shouldn't be too hard.
Post Reply