Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Maya® / MEL / Removing first and last character in string?
  RSS 2.0 ATOM  

Removing first and last character in string?
Rate this thread
 
62322
 
Permlink of this thread  
avatar
  • wesm
  • Posted: 28 November 2011 03:28 AM
  • Location: Louisville Kentucky
  • Total Posts: 204
  • Joined: 22 August 2006 01:27 PM

Hey,

I am trying to remove the first and last character in a string. I want to do this as efficiently as possible so the it will execute quickly in my overall script. I am trying to use the substitute command, but can’t figure out the reg expression.

The following line will remove the first character.

substitute("^[(\.)]"$command"");

This line will remove the last character in the string.

substitute("[(.)]*$" $command,"");

How can I combine these two reg expressions so that it will remove the “.” character from the beginning and end of my string.

Thanks!

Wes



Wes McDermott | 3D Artist | Author
http://the3dninja.com
http://the3dninja.com/blog

Replies: 0
avatar
  • ldunham1
  • Posted: 28 November 2011 04:45 AM

are you limited to using substitute for speed?
you could use:

substring $command 2 (`size($command)`-1);

I did a speed test and there was no real difference between substituting one character or using substring.
Speed test was over 1000 iterations.



Lee Dunham | Character TD
ldunham.blogspot.com

Replies: 1
/userdata/avatar/g4b0qfa63_Ninjatar.png

No real reason for substitute. I’ll use substring instead. Thanks much for the help!

Author: wesm

Replied: 28 November 2011 05:24 AM