strings method

BlitzMax Forums/BlitzMax Beginners Area/strings method

GuoQiang(Posted 2005) [#1]
Strict
Local str:String="***** Hello *****"
str.replace("*","=")
Print str

output: ***** Hello *****
I hope output : ===== Hello =====


Floyd(Posted 2005) [#2]
The Replace method returns a new string.
Strict
Local str:String="***** Hello *****"

Print

str.replace("*","=")
Print str

str = str.replace("*","=")
Print str
It's not easy to find this in the documentation. Look in the Language reference, Strings section. There is a list of string methods, including this one:

Replace:String( subString:String,withString:String )

The Replace:String tells you that Replace returns a String value.


bradford6(Posted 2005) [#3]
blitz is a compiled language and hence the objects are immutable.

you cannot generally change an object in place. you need to create a new object to replace the existing one.

even slices use this feature.

str = str.replace("*","=")

hands the results of the function to the new str and destroys the 'old' str


GuoQiang(Posted 2005) [#4]
Thanks, I have understand.