Returning element X from a string?

BlitzMax Forums/BlitzMax Beginners Area/Returning element X from a string?

Bukky(Posted 2006) [#1]
Hello,

Suppose that I have a string which consists of "0, 1, 2, 3, 4, 3, 2, 1". How do I parse the integer at, lets say, location 5?

What I'm trying to do is traverse the string and put only the numerical values of the string into an array of integers. Problem is, when I try to do:

an_array[k] = a_string[x]

an_array[k] gets assigned an ascii value which cooresponds with the character at location x of a_string. How can I assign the actual integer of a_string[x] to an_array[k]?


assari(Posted 2006) [#2]
How about something like this?
Local a_string:String="0, 1, 2, 3, 4, 3, 2, 1"+", "

Local an_array:int[100]

Local x:Int=5

an_array[x]=Int(Chr(a_string[x*3]))

Print an_Array[x]



FlameDuck(Posted 2006) [#3]
Suppose that I have a string which consists of "0, 1, 2, 3, 4, 3, 2, 1". How do I parse the integer at, lets say, location 5?
Use the code archives Luke. The simplest way would be to use a 'String Tokenizer' and load the array with tokens, one at a time.

If you just need the fifth position, (which is a space) you can use string slices, ala. myString[5..6] to extact the character you want.