Adding Chr(0) to strings

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
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 PB.

Is it possible for strings to contain Chr(0) characters?
At the moment the following returns 0 instead of 10... but
I need a string to contain Chr(0).

Code: Select all

For r=1 To 10
  a$=a$+Chr(0)
Next
Debug Len(a$)

PB - Registered PureBasic Coder
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 don't think it's possible for strings to contain null characters as these are reserved to terminate a string, you probably have to use a memorybuffer to get what you want...
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 PB.

> I don't think it's possible for strings to contain null characters
> as these are reserved to terminate a string, you probably have to
> use a memorybuffer to get what you want...

Ah, okay. I was trying to use a string simply because I want to
use ReplaceString to change some data in a string... is there an
easy way to do a search/replace in a memory block? Or is this a
good request for a future command? :)


PB - Registered PureBasic Coder
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.
Originally posted by PB
Ah, okay. I was trying to use a string simply because I want to
use ReplaceString to change some data in a string... is there an
easy way to do a search/replace in a memory block? Or is this a
good request for a future command? :)
I did a small procedure a while ago that search and replace data in a memoryblock, you can find it on the resource site under the snippet section, it's called "findandreplacemem". With some modifications you can customize it to your needs...
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 PB.

> I did a small procedure a while ago that search and replace data in
> a memoryblock, you can find it on the resource site under the
> snippet section, it's called "findandreplacemem".

Thanks, I worked it out but I'll take a look at your version.


PB - Registered PureBasic Coder
Post Reply