Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / basic array question

Years of Service
User Offline
Joined: 8th Nov 2011
Location: u tell me?
Posted: 8th Nov 2011 09:50
first post, so hello everyone

i have a pretty basic array question, might even be kinda dumb
say i have a string containing some data, like below:

stringsomething = "1,23,64,20,11"

and i would like to get that data out of the string as an array, something like below:

for each "array thingy" in stringsomething
inc count
actionHere(count) = "array thingy"

how would i do that? i guess what im asking is how to save an array as a single string, and "open" it again
im a newbie at db, but i have some experience with programming.

"hello world"
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Nov 2011 14:56
You want to save and load arrays? There are commands for that:

save array
load array


Years of Service
User Offline
Joined: 23rd Jul 2006
Posted: 8th Nov 2011 19:34

Hello, welcome!

This will be a fairly detailed explanation, so bare with it if it's written for more of a novice. If you mean converting a string to an array, what you generally have to do is "parse" the array into chunks that you want to store in the array. Parse just means separate or break down.

So, in your example:

stringsomething = "1,23,64,20,11"

We'll assume that you want each number to go into it's own array index. The first thing to note is that a single string in DBC maximum length is 255 characters. Keep that in the back of your find.

So the first thing we need to do is determine how long the array should be. If you already know, then just dimenion the array to the proper size:

dim myarray(100) or whatever size

If you don't know, then we'll have to figure it out based on the string. In your example, your string elements (the numbers) have a delimiter separating them - the comma ',' . A delimiter is a separator. It could be a space, a tab, a semicolon, really any character at all. It's your job to read the delimiters so you can figure out how to parse the string.

Back to the length of the array. Count the delimiters using the built in command MID$() and then dimension the array to the correct size. Based on the type of numbers (they look like integers) I'll create the array to hold integers.

Anyway, once we have the array size, we can parse the string and store it. Here's the whole code:

This is a fairly straight forward way that should work most of the time depending on the complexity of your data. If you search the forums, you will find string libraries that others have made to make the handling of strings easier. There is no

Instr(pos,SUB$,BODY$) or

natively in DBC, but they aren't too hard to make, and you will find lots of examples of them if you search through the forums.

Enjoy your day.
Years of Service
User Offline
Joined: 8th Nov 2011
Location: u tell me?
Posted: 9th Nov 2011 09:48

that was exactly what i was looking for
thank you very much, i thought it would be simpler, but i can really use the code you provided!
i remember doing something like this for a website in, there it was pretty simple by selecting a separator, but its ages ago.
anyway, thanks a lot

oh and for saving and storing arrays, i found this topic helpfull: ( maybe someone reading this will to

"hello world"

Login to post a reply

Server time is: 2020-08-15 12:21:18
Your offset time is: 2020-08-15 12:21:18