• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

how to extract a word from a textfield

Guest
Nov 23, 2015 Nov 23, 2015

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.

TOPICS
ActionScript

Views

428

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 23, 2015 Nov 23, 2015

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.

Votes

Translate

Translate
Community Expert ,
Nov 23, 2015 Nov 23, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 23, 2015 Nov 23, 2015

Copy link to clipboard

Copied

Thank you kglad, i will see it

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 23, 2015 Nov 23, 2015

Copy link to clipboard

Copied

you're welcome.

p.s when using the adobe forums, please mark helpful/correct responses, if there are any.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 23, 2015 Nov 23, 2015

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 23, 2015 Nov 23, 2015

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 24, 2015 Nov 24, 2015

Copy link to clipboard

Copied

Yeah, with friends help too, it works . Thank for your help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2015 Nov 24, 2015

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines