Brian
asked on
How to break up a word wrapped textbox for output in a VB.net program
I have a multiline textbox that could word wrap (user could type in a paragraph of text). The problem is, when a line of text word wraps, I have no idea when that happens. And because of this, when I output the line, it may run off the screen. I have a string array that I am adding my output to, then when all lines are added, I will loop thru the array outputting the lines.
What I would like to do for the multiline texbox is check if the string is more than 155 characters. If the string is over 155 characters, I would break it at the first space that exists prior to the 156th character and add the text before that space to the array. The remaining text would need to be tested to see if it's longer 155 characters. If it is, it would need to be broken up the same way, if not, the remaining characters would be added to the next element in the array.
The code would look something like this...
What I would like to do for the multiline texbox is check if the string is more than 155 characters. If the string is over 155 characters, I would break it at the first space that exists prior to the 156th character and add the text before that space to the array. The remaining text would need to be tested to see if it's longer 155 characters. If it is, it would need to be broken up the same way, if not, the remaining characters would be added to the next element in the array.
The code would look something like this...
dim strAnswer1 as string = texbox1.text
if strAnswer1.length > 155 Then
add first part of string to strArray(i)
handle remaining text in strAnswer1
else
strArray(i) = strAnswer1
end if
I think there would need to be a loop where I would increment the "i" variable, which is the count, but I'm unclear how I should do this. Basically what I need to do is breakup a string that might be longer than 155 characters (could be 500+ characters) into lengths less than 156 characters and add them to a string array, but I need the break to be at a point where there is a space. Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much for your expertise!
ASKER