all groups > flash (macromedia) > july 2003 >
You're in the

flash (macromedia)

group:

How to detect a string contains certain string


How to detect a string contains certain string Baba
7/31/2003 10:38:23 PM
flash (macromedia):
Hi to all:

How can I detect a string contains a certain string.

I want my user to input a sentence and as long as this sentence contains a
certain word(s) I am looking for, that the user is allow to move to some
frames.

for example:

If the user entered "My name is Larry James".

And the word I am looking for is Larry, is there a function to scan through
the whole sentence and detect the presence of Larry?

sample code would be appreciated.

thanks

Baba.

Re: How to detect a string contains certain string Byron Canfield
8/1/2003 9:25:05 AM
If you don't want it to consider the match found when uppercase doesn't
match lowercase:

booFound = Boolean(strSentence.indexOf(strSearch)+1);

If you want "larry" to be considered equivalent to "Larry":

booFound =
Boolean(strSentence.toLowerCase().indexOf(strSearch.toLowerCase())+1);

Application of the latter, which will show you the result:

strSearch = "larry";
strSentence = "My name is Larry James";
booFound =
Boolean(strSentence.toLowerCase().indexOf(strSearch.toLowerCase())+1);
trace("strSearch: "+strSearch+" | booFound: "+booFound);


--
"There are 10 kinds of people in the world. Those who understand binary
numbers and those who don't."
----------------------
Byron "Barn" Canfield
http://www.headsprout.com
Flash examples: http://www.byronc.com/flash5
[I do not respond to private emails regarding issues for which the
appropriate venue is this newsgroup, nor do I reply to posts by email.]




[quoted text, click to view]

Re:How to detect a string contains certain string Iwein
8/1/2003 11:05:31 AM
AddThis Social Bookmark Button