PDA

View Full Version : Isolate name


JFFORTIN
06-13-2006, 06:11 PM
i want to isolate some string in a array
{"Hello_Boobby",Hello_Shawn","Steve","Martin"}
how i isolate thsoe string who start with Hello ?

thx
Cheers
JF

animationrigs
06-13-2006, 06:46 PM
You can loop through the array and use regular expressions to match on "hello" for example. Depending on what you need, you can put the results in a new array or do whatever you need to in your loop.
loop:
I mean for loop
regular expressions, check out:
match
gmatch

Segmoria
06-14-2006, 04:33 PM
Another suggestion would be to use the startsWith command so as to check whether each string starts with a "Hello_" and then copy the strings that don't to another array using something like the following:
{
string $allStrings[] = {"Hello_Boobby","Hello_Shawn","Steve","Martin"};
string $nonHelloStrings[];

int $stringsToRemove[];
for ($i = 0; $i < `size($allStrings)`; $i++)
{
if ( (startsWith($allStrings[$i], "Hello_")) == 0 )
{
$nonHelloStrings[$i] = $allStrings[$i];
}
}
}

JFFORTIN
06-14-2006, 06:38 PM
thx Segmoria
i use finally

if( `gmatch $obj[$i] "Hello*"`)
{
do something;
}

works perfectly


i saw the startstring in the help after i use gmatch

cheers

CGTalk Moderation
06-14-2006, 06:38 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.