I have
to test this, but I think substring is probably adequate for most
purposes. The other way to go would be to is to use a char
array, as below. I don't know which one is faster -- my hunch is it
depends on the size and number of String objects created.
char[]
c = myString.toCharArray();
int
paragraphLength = 35;
int
fullArrayLength = c.length;
Vector
splitStrings = new Vector(fullArrayLength/paragraphLength +
1);
StringBuffer splitString = null;
for(int j = 0; j < fullArrayLength/paragraphLength; j++)
{
splitString = new StringBuffer();
for(int i = 0; i <
paragraphLength; i++) {
splitString.append(c[j*paragraphLength + i]);
}
splitStrings.addElement(splitString.toString());
}
You
guys might want to test this one if you want to use it -- I may have some off by
1 errors or something...
Greg
____________________________________________________-----Original Message-----
From: Patrick Li [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 20, 2003 1:21 PM
To: JDJList
Subject: [jdjlist] String segmentation??? (was: RE: Slow: string += string)While we are talking about string concatenation, what about truncation? Is there a more efficient way to break a long string into segments than using substring()? For example, if I read a paragraph into a string and then wants to break it into line depending on the size of dialog box that will display the paragraph. What is the most efficient way of doing that?Thanks in advancePatrick Li____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________
