Remove character from end of a string

BlitzMax Forums/BlitzMax Beginners Area/Remove character from end of a string

ima747(Posted 2008) [#1]
What's the easiest way to remove just the last character from a string?


GfK(Posted 2008) [#2]
myString:String = "Hello"
myString = mystring[..Len(myString)-1]
Print myString



plash(Posted 2008) [#3]
Using Slicing.

SuperStrict

Framework brl.standardio

Local value:String = "Hello World"
Local stripped:String = value[..value.Length - 1]

Print(value)
Print(stripped)



Brucey(Posted 2008) [#4]
Local s:String = "12345678"

s = s[..s.length-1]

Print s



ima747(Posted 2008) [#5]
lol, thanks guys, your speedy responses never cease to amaze ;0)


*(Posted 2008) [#6]
you could do:
String = Left$( String, Len( String )-1 )


too


plash(Posted 2008) [#7]
@EdzUp: Left() uses slicing anyways, the overhead call is probably going to loose a little speed :P


Grey Alien(Posted 2008) [#8]
or

String = mid(String,1,Len(String)-1)


This is classic BASIC like you'd use on an 8-bit computer.


Warpy(Posted 2008) [#9]
eww, it is also horrible to look at.


SebHoll(Posted 2008) [#10]
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.


Brucey(Posted 2008) [#11]
you may as well cut out the middle man

Except that many folks are stuck in their old ways ;-)


boomboom(Posted 2008) [#12]
A lot of people like Blitz because of the middlemen :)


SebHoll(Posted 2008) [#13]
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... ;-)


Grey Alien(Posted 2008) [#14]
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.