View Full Version : how can I remove the last letters or numbers on a string?
shenmue 10-12-2007, 01:20 AM Heluuu again
When I create follicules I get ramdom numbers as suffix.For example when I create follicoles on a poligons they are named : follicule5001, follicule5002,etc..etc...I know I can just rename them,but I am doing that by mel,and I want to remove the las 4 digits so I can create clean nomenclatures,like follicule1,follicule2,follicule3,etc....
:shrug: and no idea...
|
|
harmless
10-12-2007, 04:25 AM
string $s = "foo5999";
$s = `substring $s 1 (size($s)-4)`;
Blue Bird
10-12-2007, 08:59 AM
This is from ewertb.com under MEL Expressions:
string $node = "pCube1|pCubeShape223";
string $noSuffix = `match ".*[^0-9]" $node`;
// Result: "pCube1|pCubeShape"Cheers!
P.S. Brian, where are you?! :sad:
shenmue
10-12-2007, 01:26 PM
great stuff guys,thanks.:)
strarup
10-24-2007, 11:20 AM
Hi,
well there is a lot of different ways to do it... e.g.
here is a little script which uses the endString cmd to get the last 4 digits...
proc doDaRemoveLastNrOfDigits(string $daName, int $daNr, string $daObjType)
{
string $daObj[] = `ls -typ $daObjType ($daName+"*") `;
//sorting them if they haven't been selected in order number 1,2,3 etc...
$daObj=sort($daObj);
string $daRemoveStr, $daNewObjStr;
for($i=0;$i <size($daObj); $i++)
{
//get the last 4 chars from your string if "int $daNr" = 4...
//e.g. follicule5001 = 5001...
$daRemoveStr = endString($daObj[$i], $daNr);
//using substitute to remove the last 4 numbers from the string
$daNewObjStr = substitute($daRemoveStr, $daObj[$i], "");
//rename the object with the new string
rename $daObj[$i] ($daNewObjStr+($i+1)) ;
}
}
doDaRemoveLastNrOfDigits("follicule", 4, "transform");
or if the objectType is follicle... use this instead...
doDaRemoveLast4Digits("follicule", 4, "follicle");
I have made it a bit more common so you can choose the amount of numbers... the objectname and objectType
to make the changes to... :)
hope you can use it...
regards
Strarup
shenmue
10-24-2007, 12:21 PM
thanks,I am going to try it and learn how you did it.:bounce:
strarup
10-24-2007, 12:27 PM
Hi,
you're welcome... and good luck with it... :)
my internet time is about over now... and I will properly first be back on friday...
however if you have some more questions or whatever.. just ask and I will see if I can do anything to help with it... :)
regards
Strarup
CGTalk Moderation
10-24-2007, 12:27 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.