all groups > flash actionscript > november 2004 >
You're in the

flash actionscript

group:

IndexOf action help in Flash 6 (MX)



Re: IndexOf action help in Flash 6 (MX) MJQTREBLE
11/26/2004 7:10:20 PM
flash actionscript: Try splitting the query string into seperate words i.e.

string = "Philip K. Dick";
query = "Philip Dick";
split =query.split(" ");
for (var searchword in split){
if (string.indexOf(split[searchword])>=0){
trace(split[searchword]+" is present");
}
}


IndexOf action help in Flash 6 (MX) Luka
11/26/2004 7:25:51 PM
Im using indexOf() action in flash to create search. It works fine with one
word, but does anyone has an idea how to use it for search with multiple
word query? Because when i'm searchin the text about, lets say "Philip K.
Dick", if i type any of this words separetly its cool, but there is no
result if im searching for Philip Dick because: Philip Dick != Philip K.
Dick, as a string ;)

Any help, just a hint or an idea is appreciated!

Thanks
Luka





Re: IndexOf action help in Flash 6 (MX) Luka
11/26/2004 10:51:45 PM
The script works, but if I type "Philip Dick" and split it on two words, for
every one of the word result is shown. I was trying to show just one result
if those words were found in a string. Do you know quick solution?
Nevertheless, thanks!!!

Luka


Re: IndexOf action help in Flash 6 (MX) Luka
11/28/2004 2:42:09 AM
I wasn't specific in my last post, let me rephrase my question:

If i use:

[quoted text, click to view]

Results are duplicated because of the FOR action, and for each word (string)
in "split" array result will be duplicated. So in this particular example in
the output window will be shown "Philip is present" and "Dick is present",
while im trying to display only "Philip Dick is present in Philip K. Dick".
Can you help me with that?

Thanks
Luka



Re: IndexOf action help in Flash 6 (MX) J_o_h_n_n_y
11/28/2004 3:32:07 AM
try this:

string = "Philip K. Dick";
query = "Philip Dick";
split =query.split(" ");
wordsFound = 0;
wordsNeeded = split.length;
for (var searchword in split){
if (string.indexOf(split[searchword])>=0){
wordsFound ++;
}
}
if (wordsFound >= wordsNeeded) {
trace("Found it");
}

Re: IndexOf action help in Flash 6 (MX) NSurveyor
11/28/2004 8:30:20 PM
Try this:
//========================================
string = "Philip K. Dick";
query = "Philip Dick";
split =query.split(" ");
wordsFound = 0;
wordsNeeded = split.length;
for (var searchword in split){
if (string.indexOf(" "+split[searchword]+" ")>=0){
wordsFound ++;
}
}
if (wordsFound >= wordsNeeded) {
trace("Found it");
}
//========================================
Re: IndexOf action help in Flash 6 (MX) Luka
11/28/2004 8:33:31 PM
Thank you Johnny, you helped me a lot! It works perfect!!!
I have one more question for you:

For example, if I search next strings using IndexOf() action combined with
your script:

Philip Dik Do Androids Dream Of Electric Sheep
Macromedia Dreamweaver For Beginners

for query "Dream", I'll get both sentences (strings) as search result
(containing "dream" and "dreamweaver").

How can I modify indexOf() action to match exact word only so the result for
query "Dream" would be only first string:

Philip Dik Do Androids Dream Of Electric Sheep?

Thanks
Luka


[quoted text, click to view]



Re: IndexOf action help in Flash 6 (MX) NSurveyor
11/28/2004 8:35:59 PM
Just realized a flaw in my script: The first word of the string to search
wouldn't count as being found even if it was one of the search words)
Use this:
//========================================
string = "Philip K. Dick";
query = "Philip Dick";
split =query.split(" ");
wordsFound = 0;
wordsNeeded = split.length;
for (var searchword in split){
if(string.indexOf(split[searchword]+" ") == 0){
wordsFound ++;
}else if (string.indexOf(" "+split[searchword]+" ")>=0){
wordsFound ++;
}
}
if (wordsFound >= wordsNeeded) {
trace("Found it");
}
//========================================
Re: IndexOf action help in Flash 6 (MX) Luka
11/28/2004 11:21:47 PM
Thanks once again NSurveyor ;)

Luka


[quoted text, click to view]

AddThis Social Bookmark Button