Setting the value of specific string letters.

BlitzMax Forums/BlitzMax Beginners Area/Setting the value of specific string letters.

Ryan Burnside(Posted 2009) [#1]
It seems that one can read the value of a string at any index however one cannot change a string's letter at a given index.

'does not work
Local s:String = "xxx"
s[1] = "a"

'does not work
Local s:String = "xxx"
s[1] = 64



Both give the error
"Compile Error: Expression must be a variable"


Perturbatio(Posted 2009) [#2]
Not quite what you're looking for but...

Local str:String = "dord"
SetIndex(str, 0, "w")
Print str

Function SetIndex(str:String Var, index: Int, newChar:String)
	str = str[0..index] + newChar + str[index+1..]
End Function



Ryan Burnside(Posted 2009) [#3]
Thank you so much. This is for a text buffer for a text only game so this will help.