PDA

View Full Version : Delete End Character of String


CoreyJAvitar
05-23-2008, 10:19 PM
Hey all!
I've wondered how to do this multiple times, and I usually forget after I figure it out, but I'll post here in case anybody else is wondering.
I wanted to remove the end character from a string (in this case a carrage return).
There's no explicit command to do this, so you gotta kinda hack job it:

$mystring = "IamAwesome";
int $num;
$num = `size($mystring)`;
$num -=1;
$newstring = `substring $mystring 1 $num`;

There you go!
I hope someone finds this info useful.

greatPumpkin
05-24-2008, 08:54 AM
There's a simpler way to do this:
http://ewertb.soundlinker.com/mel/mel.011.htm


or if you're not talking carriage returns and you just want to walk back from the end of a string a little in line python works really well:

i.e.
string $source = "onetwothree";
$source = python("'" + source + "'[0:-1]");

the -1 basically signifies the last character in the string, so you can walk back from the end and 0 means the first character.

Gravedigger
05-24-2008, 09:08 AM
hmm....this is just more or less the way it's done with most programming/scripting languages....

you should combine all those commands:

$mystring = "IamnotthatAwesome";
$newstring = `substring $mystring 1 (size($mystring)-1)`;


grs Gravedigger

CGTalk Moderation
05-24-2008, 09:08 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.