Remove character from end of a string
BlitzMax Forums/BlitzMax Beginners Area/Remove character from end of a string
| ||
What's the easiest way to remove just the last character from a string? |
| ||
myString:String = "Hello" myString = mystring[..Len(myString)-1] Print myString |
| ||
Using Slicing.SuperStrict Framework brl.standardio Local value:String = "Hello World" Local stripped:String = value[..value.Length - 1] Print(value) Print(stripped) |
| ||
Local s:String = "12345678" s = s[..s.length-1] Print s |
| ||
lol, thanks guys, your speedy responses never cease to amaze ;0) |
| ||
you could do:String = Left$( String, Len( String )-1 ) too |
| ||
@EdzUp: Left() uses slicing anyways, the overhead call is probably going to loose a little speed :P |
| ||
orString = mid(String,1,Len(String)-1) This is classic BASIC like you'd use on an 8-bit computer. |
| ||
eww, it is also horrible to look at. |
| ||
If you have a look at the code in BRL.Retro, you'll see that the Mid$() function Grey Alien is using uses slicing under the hood anyway, so you may as well cut out the middle man and just call it directly yourself. |
| ||
you may as well cut out the middle man Except that many folks are stuck in their old ways ;-) |
| ||
A lot of people like Blitz because of the middlemen :) |
| ||
lol, that is true, but going back to the original question... What's the easiest way to remove just the last character from a string? Slicing is definitely easier than the Mid() function... Less characters to type for a start... ;-) |
| ||
For me the Syntax of Mid is easier to understand than slicing. I have to think about slicing whereas Mid I do not, but that's from years of using Mid or the equivalent in Delphi. |