PDA

View Full Version : how to parse a string ?


a-sais-pas
02-24-2003, 08:11 PM
hi,

I am sure that someone will be able to help me on that...

I would like to do the following:
parse a sentence and then put each word in a variable

for example, let's say I have I enter that sentence in a text field:

I am happy

What I would like to do is cut that sentence (the space is the type that indicates that one word in finished) and then allocate :

arg1 = "I";
arg2 = "am";...

Hope someone will help me

thanks a lot

a-sais-pas

CyanBlue
02-24-2003, 08:35 PM
Howdy...

You can use split() function to do what you need to do... This might give you a starting point...str = "I am happy.";

tempArray = str.split(" ");

trace(tempArray + " : " + tempArray.length);I,am,happy. : 3As you can see the results gets to the array and if you see the last item of the array carefully , you can see the '.' at the end which I have put it right there intentionally... You sometimes need to get rid of the punctuational symbols such as , ; . " ' ? ! and so on which you can do with the if statement after the array has been made...

Let me know... :)