String to Char Array function, anyone?

BlitzMax Forums/BlitzMax Beginners Area/String to Char Array function, anyone?

pappavis(Posted 2006) [#1]
Does BlitzMax have a function to convert a string to a string array?

Anyone familiar with microsoft dotnet will know one can do something like:
string[] strMyText = "Make me an string array".ToCharArray();

Whats the equvilant of ToCharArray() for BlitzMax?

TIA,
pappavis.


puki(Posted 2006) [#2]
Ah - is this a BMax question? If not then B3D has no such direct command.


skidracer(Posted 2006) [#3]
string.ToCString()


FlameDuck(Posted 2006) [#4]
Incidently, you might not really have to, as strings are indexable / slicable already.

So you could just do strMyText[0..1] and you'll get an "M", or strMyText[0..4] and get "Make".


skidracer(Posted 2006) [#5]
Oops, misread the question, there doesn't seem to be a ToBytes or ToShorts methods in BlitzMax.


TomToad(Posted 2006) [#6]
Don't know if this is what you're wanting, but you can access each character's ASCII code by accessing the string like an array.
Local MyString:String = "Hello World!"

For Local t:Int = 0 To Len(MyString) - 1
 Print Chr(MyString[t])+" "+MyString[t]
Next

If you want to make an actual array of strings with each element conatining one character of another string, you could do something like this
Local MyString:String = "Hello World!"
Local MyStringArray:String[]

MyStringArray = New String[Len(MyString)]
For Local t = 0 To Len(MyString)-1
 MyStringArray[t] = Chr(MyString[t])
Next

For t = 0 To Len(MyString) - 1
 Print MyStringArray[t]
Next