Page 1 of 1

String arrays

Posted: Fri Jul 18, 2003 5:24 pm
by geoff
I want to create a string array a$(100000) and populate it with strings of
varying length. Most have just a few characters but several have many
thousands. Some of these strings contain chr(0).

This is easy in most Basics but PB does not allow chr(0) within strings.

Is there a simple alternative?

Posted: Fri Jul 18, 2003 5:41 pm
by Karbon
I don't *think* there would be any way to include a NULL character within a string since NULL indicates end-of-string. I can suggest maybe escaping the NULLs (rather, replacing the NULLs with something) and re-assembling then when they're used?

Good luck!

Posted: Sat Jul 19, 2003 3:42 pm
by geoff
Thanks for the suggestion Karbon but it won't work here because the
strings contain all 256 possible characters (they are encrypted)

Anyone else have a neat solution?

Posted: Sat Jul 19, 2003 3:55 pm
by Pupil
Maybe you can do an array of pointers instead and allocate memory for each entry in the array to hold the string data..

Posted: Sun Jul 20, 2003 3:22 pm
by geoff
Maybe you can do an array of pointers instead and allocate memory for each entry in the array to hold the string data..
Yes, that's probably the best way to do it.

But, this is equivalent to writing your own pseudo-string routines. Sadly, the PB string functions would not work on these pseudo-strings so you would have to write versions of them as well.

Alternatively, you could manipulate the memory bytes directly using pointers. But the main advantage of using a high level language is to avoid this sort of thing because it is slow to write and error prone.

This leaves me thinking that PB strings should allow null characters. You could still have a null as the last character if you wanted to, for compatibility with C, for example

Fred, why not allow nulls in strings like other Basics?
Basic is clearly superior to C in this respect, so why do it the C way?

Can anyone see a problem with this idea?

Posted: Mon Jul 21, 2003 2:34 am
by Karbon
This leaves me thinking that PB strings should allow null characters. You could still have a null as the last character if you wanted to, for compatibility with C, for example

Fred, why not allow nulls in strings like other Basics?
Basic is clearly superior to C in this respect, so why do it the C way?

Can anyone see a problem with this idea?
Yea, backwards compatibility would probably be the single biggest problem :-)

Regardless, there has to be something to indicate end-of-string and NULL is pretty widely used an accepted as that character.. However toss this into the feature request forum and see what happens!

Posted: Mon Jul 21, 2003 9:25 pm
by Gantry
Moving away from zero terminated strings would, I imagine, cause Fred working a long time fixing something that's not broken. Try to call the API with a string like that. Is it possible to convince the API that zero is not the termination character? I don't know.

Sure, it could be neat being able to include a NULL character but what's the cost (rewriting the compiler) vs the benefit (sometimes useful)?

Then again, I have been known to be wrong from time to time...

Have a nice day all!

/Gantry

Posted: Tue Jul 22, 2003 2:57 am
by aszid
hmmmm.....

well, i think it would be a cool idea to have strings that could contain nulls, but the best approach would probably be a new type of string, rather than changing how current strings work.

something like nullstring.ns perhaps? i know for certain that it would be very usefull to me.