after reading this great tutorial about string
[http://www.blitzmax.com/Community/posts.php?topic=42058]
I've been wonder what if I wana remove a letter in the middle of the string? Is there an easy way to do this or do I have to copy from end of the string to the letter in question then delete from letter to end and then put in what was copied?
local text:string = "Welcome"
... use this
Thanks for the help :)
You can use the replace method
Local MyString:String = "Hello"
MyString = MyString.Replace("e","")
Or, if you want to remove a letter from a specific position then you can use slices.
Local text:String = "Welcome"
' remove the 4th letter (c)
' remembering that slices are zero indexed
text = text[..3] + text[4..]
Print text
What Brucey said. Done much Python programming?
Never did python
Nice Brucey, I knew of replace but thats bad if you have two of teh same letter in a string.
one thing i just noticed
' remembering that slices are zero indexed
What does that mean exactly? o.o
text = text[..3] + text[4..] wouldn't it be
text = text[..3] + text[5..] to remove 4th letter
must have to do with the zero indexed thingy which i dunno what it means.
nah because text[..3] will hold characters at indexes 0, 1, and 2 while text[4..] will hold characters at indexes 4, 5, ....
The slice function works from index a inclusive to index b exclusive, so text[1..4] will be indexes 1, 2, 3.
Hope it helps
oh
text[..3] everything before 3 not including 3
text[4..] everything above 4 including 4
I think i get it :o
first number always included, last number never included
so if no number is writen at start 0 is included but whatever number is writen at end is never included hmm
I think i get how slice works but even if you said to me (slices are zero indexed) it means nothing to me. xD
' remove the 4th letter (c)
' remembering that slices are zero indexed
This was meant simply as a reminder that the first three items are numbered 0,1,2 rather than 1,2,3.