PDA

View Full Version : String manipulation - functions (edited title)



masteR14
March 31st, 2002, 04:37 AM
I don't know if it's possible but i would like to take the first, and the last letter from a word and compare it, it would be very usefull to me, please help me

ilyaslamasse
March 31st, 2002, 05:39 AM
There are a few String methods you can check in the Actions Panel > Function > String.
About your problem, let's say you have a DYNAMIC text box on the scene that you called "text", with the word "Salut" in it. If you put this code in teh first frame of the timeline :
a = text.length ;

b = text.charAt(0) ;

c = text.charAt(a-1) ;

trace (a) ;

trace (b) ;

trace (c) ;you'll get 5, S, t.

pom 0]

ilyaslamasse
May 26th, 2002, 12:58 PM
More about Strings methods. Let's say that your Dynamic Textbox 'text' now contains "azertyuitop".
trace (text.substr (2,3)) ;

//returns 'ert' that is to say 3 letters from the letter indexed as 2, that is to say the

//3rd because the index start from 0



trace (text.substring (2,4)) ;

//returns 'er' that is to say letters from index 2 to 4-1. That's how it works, don't ask me why.



trace (text.indexOf ("t")) ;

//returns 4 -> first instance of t.



trace (text.lastIndexOf ("t")) ;

// returns 8, the last index of the stringpom 0]