Oh ok. You didn't actually have the charName value and you just want to
remove the last component separated by an underscore.
I don't really see the reason to try and first parse the token out of the
string, and then use it to remove it from the original. You can just use a
regex to strip it:

string $srcFile = "blabla_blabla_charName.fbx";
string $saveFileString = basename( $srcFile, ".fbx" );
string $saveFileName = `substitute "_[a-zA-Z0-9]+$" $saveFileString ""`;

​
Or you can completely avoid regular expression and just split the string on
underscore, and join it back without the last component:

string $srcFile = "blabla_blabla_charName.fbx";
string $tokens[];int $size = tokenize($srcFile, "_", $tokens);
stringArrayRemoveAtIndex($size-1, $tokens);
string $saveFileName = stringArrayToString($tokens, "_");

​



On Sat, Jul 5, 2014 at 7:16 PM, lala <[email protected]> wrote:

> string $srcFile = "blabla_blabla_charName.fbx";
> string $saveFileString = basename( $srcFile, ".fbx" );
> string $charName = "_" + `substitute "^[^.]*\\_" $saveFileString ""`;
> string $saveFileName = `substitute $charName $saveFileString ""`;
> print $saveFileName;
>
> apparently its solved now with your help. but if you look at line 3, its
> cheap (adding "underscore manually"). but atleast its working.
> generally, i am sure, regex in line 3 again (second part) can solve
> it..but still, thanks anyways, really appriciate your prompt responses.
> always. thats only reason, posting here is more fun than anywhere else.
>
> On Saturday, 5 July 2014 11:55:36 UTC+5, Justin Israel wrote:
>
>>  That's what you wanted right?
>>
>>>  options, visit https://groups.google.com/d/optout.
>>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/a200980e-cd6a-4c72-bd26-c3954639cd3e%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/a200980e-cd6a-4c72-bd26-c3954639cd3e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1fq6A7%2Bc5UoJ7YddPkQO1TC97ETLA1R%2BhiQgzX%3DOL6CA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to