PDA

View Full Version : MEL: I want to extract all names that end with “_END”


pigbelly
04-02-2003, 12:48 PM
I have an array with names and I want to extract all names that end with “_END” and put them in another array???

Any ides!!!???

/Tommie

X-Tender
04-02-2003, 01:41 PM
int $k = 0;
string $text; //your string that you want to find in an array string
string $array1[]; //array that has all your values
string $array2[]; //array that have the filterd data
for ($i=0;$i<=size($array1);$i++)
{
if (gmatch $array1[$i] ("*"+$text+"*"))
{
$array2[$k] = $array1[$i];
$k++;
};
};



This must work!

-XT

danielpk
04-02-2003, 01:42 PM
Hi,

It is quite simple:
string $names[]; // your array with names
string $endNames[]; // your "new" array containing the names ending with "_END"
int $inc; // an integer variable for incrementing

// now we build a for loop
for ($name in $names) // $name will be the next item of $names for every loop
{
// an if statement will only execute its command if the condition is true (or 1)
if (eval("match \"_END$\" "+$name) != "") // this is the condition.
{
// "!=" means "if it is not equal" it will be true
// and the following command will be executed only then
$endNames[$inc++] = $name;
}
}
You can even make it non case sensitive this way:
string $names[], $endNames[];
int $inc;
for ($name in $names)
if (eval("match \"_[eE][nN][dD]$\" "+$name) != "") // here is the only real change!
$endNames[$inc++] = $name;

I used "eval" because I found that, if the strings get too long, it will not work in the traditional way.

If you try it out in the script editor, you should clear $endNames ("clear $endNames;" and set $inc to "0" ("$inc = 0;") before the loop.

Good luck.

Daniel

alexx
04-02-2003, 01:55 PM
pigbelly:

we have a special MEL sub-forum here.. just post stuff like that in there.

cheers

alexx

pigbelly
04-02-2003, 08:44 PM
Where????

/Tommie

X-Tender
04-02-2003, 09:15 PM
there!!!
http://www.cgtalk.com/forumdisplay.php?s=&forumid=89

CGTalk Moderation
01-14-2006, 07: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.