PDA

View Full Version : testing equality


flxeken
03-16-2005, 01:35 PM
Does anyone know if there is a function in actionscript to test if one expression contains another expression?
In director it was simply called "contains" and worked something like this:

test="felix"
fullName="felix af ekenstam"
if (fullName contains test){
trace(fullName+" contains "+test)
}

i have failed to get a simple thing like this to work with actionscript, i ahve to do very stupid long for loops to check everythin.. very annoying. Would be happy for some help..

Felix

senocular
03-16-2005, 01:39 PM
by expression, do you mean string?

You can use indexOf for Strings. It returns a position, though, not true or false (look it up in Flash help). Basically you see if it returns -1 or not.

nthpixel
03-18-2005, 12:46 AM
if(fullName.indexOf(test) != -1)
{
trace("success!");
}

flxeken
03-18-2005, 12:56 PM
thanks, thats exactly what im looking for. Im actually not a AS novice at all but sometimes its just so hard to find what im looking for in the help file, i dont know what to search for.. Thats when this forum is handy:)