Flag for PokeS() to suppress trailing zeroes...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Flag for PokeS() to suppress trailing zeroes...

Post by blueznl »

PokeS(*MemoryBuffer, Text$ [, Length [, Flags]])
Why not add a flag, for example #PB_Ascii | #PB_NoZero, so trailing zeroes are left out when we don't want them?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Yep, it'd be a good idea to implement such a feature. I often thought about an easy to use command that allows you to poke somewhere in the middle of a string, without cutting this string because of the stupid NULL.
Of course, there would be for example the way via pointers, but why not having a more comfortable way?
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Flag for PokeS() to suppress trailing zeroes...

Post by Demivec »

blueznl wrote:
PokeS(*MemoryBuffer, Text$ [, Length [, Flags]])
Why not add a flag, for example #PB_Ascii | #PB_NoZero, so trailing zeroes are left out when we don't want them?
Wouldn't this do the same thing, except without the benefit of flags?

Code: Select all

CopyMemory(@Text$, *MemoryBuffer, Len(Text$))
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: Flag for PokeS() to suppress trailing zeroes...

Post by tinman »

Demivec wrote:Wouldn't this do the same thing, except without the benefit of flags?

Code: Select all

CopyMemory(@Text$, *MemoryBuffer, Len(Text$))
You lose the string conversion option (e.g. Unicode->ASCII) if you use CopyMemory(). Or is that what you mean by "without the benefit of flags"?
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Flag for PokeS() to suppress trailing zeroes...

Post by Demivec »

tinman wrote:
Demivec wrote:Wouldn't this do the same thing, except without the benefit of flags?

Code: Select all

CopyMemory(@Text$, *MemoryBuffer, Len(Text$))
You lose the string conversion option (e.g. Unicode->ASCII) if you use CopyMemory(). Or is that what you mean by "without the benefit of flags"?
Yes that is what I meant.

I guess you could include the "flags" for conversion by using:

Code: Select all

PokeS(*WorkBuffer, Text$ [, Length [, Flags]])
CopyMemory(*WorkBuffer, *MemoryBuffer, MemoryStringLength(*WorkBuffer [, Flags]))
The above suggestion would probably make this Feature Request sound much more desirable that jumping through all that convoluted code to accomplish the same thing. :wink:
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

CopyMemory(@Text$, *MemoryBuffer, Len(Text$))
Ah... not Unicode friendly! :-)

I wrote my own little PokeS() variant to avoid writing that terminating zero in fields where there is not enough space, what's throwing me off-balance all the time is that you specify how many bytes to write, and then PureBasic sneakily :-) tries to help you and adds one or two zeroes :-)

It's just a request, it's not on the top of my want list :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply