Solved

How do you test for substrings in Actionscript?

Posted on 2008-06-25
3
201 Views
Last Modified: 2013-11-11
Using pseudocode now, I want the following:

var1 = "foobar"

If (var1 contains "foo") {
    result = True;
}else{
    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.
0
Comment
Question by:kharndog
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
Comment Utility
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

0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
Comment Utility
so to use your example
var var1:String = "foobar"

var result:Boolean = false;
 

result = (var1.indexOf("foo") >= 0);

Open in new window

0
 
LVL 34

Expert Comment

by:Aneesh Chopra
Comment Utility
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;
}else{
    result =  False;
}

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to how to record live broadcast.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now