PDA

View Full Version : String manipulation/truncation?


Jakobud
08-22-2003, 03:53 AM
lets say I have this:


string $str = "4:34pm";


Are there script commands I could use to manipulate this string's length? Like if I wanted to remove the "pm" from the string and just have "4:34" how could I do this? Or if I wanted to do vice versa: remove "4:34" and be left only with "pm". I'm just wondering how to change the size of the string. How to remove the front or back by any predefined length...

There has to be a way to do this.

Jakobud
08-22-2003, 04:19 AM
by the way, I am awake of Tokenize and what it does and how to use it. But I am wondering if there are any ways to do what I want to do above without using Tokenize.

mark_wilkins
08-22-2003, 07:40 AM
You have many options for manipulating strings. I recommend looking them all up in the MEL Command Reference. A few are listed below.

The direct answer to your question is that this code will chop two characters off the end.


$str = "4:35pm";
print(substring ($str,1,(size($str) - 2)));


string commands:

substring
size
strcmp
the + operator

regular expression commands:

match
substitute

other commands:

gmatch

CGTalk Moderation
01-15-2006, 10:00 PM
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.