How do you test for substrings in Actionscript?

Using pseudocode now, I want the following:

var1 = "foobar"

If (var1 contains "foo") {
    result = True;
    result =  False;

I dont know where "foo" will appear in my test variable var1, so not looking for

substring(start:Number, end:Number) : String

unless there's another way to implement this.
Who is Participating?
RobConnect With a Mentor Owner (Aidellio)Commented:
what about indexOf?

var searchString:String = "Lorem ipsum dolor sit amet.";
var index:Number;
index = searchString.indexOf("L");
trace(index); // output: 0
index = searchString.indexOf("l");
trace(index); // output: 14
index = searchString.indexOf("i");
trace(index); // output: 6
index = searchString.indexOf("ipsum");
trace(index); // output: 6
index = searchString.indexOf("i", 7);
trace(index); // output: 19
index = searchString.indexOf("z");
trace(index); // output: -1

Open in new window

RobOwner (Aidellio)Commented:
so to use your example
var var1:String = "foobar"
var result:Boolean = false;
result = (var1.indexOf("foo") >= 0);

Open in new window

Aneesh ChopraCommented:
as tagit mentioned:
actionscript uses "indexOf()" method of string in place of "contains"

below is the exact conversion of your code from  pseudocode to actionscript:

var1 = "foobar";
If (var1.indexOf("foo")!=-1) {
    result = True;
    result =  False;

if returned value is equal to -1, that's mean substring does not exist in main string.
All Courses

From novice to tech pro — start learning today.