Copy link to clipboard
Copied
Hello, i would like to extract a word in a textfield, without know the word. For example, we have a button, a textfield1 and a textfield2 :
textfield1 : "hello i like chocolat and cakes"
when i click on the button :
1. "i like" is research, and is find.
2. We take the space just after that
3. the characters (a-z) are found (chocolat)
4. and the space just after that
So, the program show "chocolat" in the textfield 2
If the sentence was : "today i want to eat chocolat, i like this", always to research "i like" the program would show the word "this" in the textfield 2.
I found on the net a "clue" to do this, but i don't pass to use it :
//Example 4-2. Retrieving the Second Word of a String
var msg = "Welcome to my website!";
firstSpace = msg.indexOf(" "); // Find the first space
secondSpace = msg.indexOf(" ", firstSpace + 1); // Find the next space
// Now extract the second word
var secondWord = msg.substring(firstSpace + 1, secondSpace);
it's to try to make a little chatbot which use words of the user, to be more "fun".
Like this :
user : hello, do you know FEabQjgra, non? yes?
flash: I don't know FEabQjgra, sorry.
It's impossible to know this word : FEabQjgra
but it's possible to find "do you know"...
So any idea to do this correctly?...
Thank you for your help.
function wordAfterStringF(s:String,tf:TextField):String{
var a:Array = tf.text.split(' ');
var i:int = a.indexOf(s);
return a[i+1]
}
and you can make this more robust by using separators different from a space.
Copy link to clipboard
Copied
function wordAfterStringF(s:String,tf:TextField):String{
var a:Array = tf.text.split(' ');
var i:int = a.indexOf(s);
return a[i+1]
}
and you can make this more robust by using separators different from a space.
Copy link to clipboard
Copied
Thank you kglad, i will see it
Copy link to clipboard
Copied
you're welcome.
p.s when using the adobe forums, please mark helpful/correct responses, if there are any.
Copy link to clipboard
Copied
hm, ok but i'm sorry but i don't see ho to use your answers in my project hm....
i think that i understand the logic of the script but i'm a little lost. "now". I will see it tomorrow
Copy link to clipboard
Copied
if you want look for the first 'word' after like in a textfield (eg, my_tf), use:
var likedS:String = wordAfterStringF('like',my_tf);
if you want to look for the first 'word' after 'eat' in my_tf, use:
var eatS:String = wordAfterStringF('eat',my_tf);
Copy link to clipboard
Copied
Yeah, with friends help too, it works . Thank for your help
Copy link to clipboard
Copied
you're welcome.