PDA

View Full Version : cutting up a sentence?



Brandon?
September 25th, 2004, 09:41 PM
Okay, is there a way to split up a sentence say 30 characters each into there own variables. I've seen this done before.
--sum up take in a variable and give out a few other variables, each 30 character cut ups of the first var.
(note: i have a sweet rpg with like every code possibly imagined and a engine thats almost done this is my only draw back i have a metheod right now but i dont like the system i have made to insert data into boxs and you hit space to get info. like a "a" button for a GB game. This will allow me to write an entire sentence.) thanks

RedSox
September 26th, 2004, 06:15 PM
One way is to use the String class and use it's methods to split strings, with either substring() or substr() for instance:

First you declare a new String variable that contains what you want to cut up:
var sTitle:String = new String("This is my test sentence");

Then you declare a second variable that will hold the cut up part. Remember that it's zero indexing, so from 0 to 5 is actually from 0 to 4 (so until it reaches 5).
var sExtracted:String = sTitle.substring(0, 5);

trace(sExtracted);

this returns "This "

So to get 30 characters each, you can create new variables (or an array) for 0 to 30, 30 to 60, etc (or something....it's already past midnight, so I can't think too clearly :) )

Brandon?
September 29th, 2004, 08:32 PM
ya im dumb, an example would help me greatly. thanks