Inserting a virtual next line symbol into a string
BlitzMax Forums/BlitzMax Beginners Area/Inserting a virtual next line symbol into a string
| ||
Hello, What I need to do is make a virtual newline or "carrage return" symbol in a string so when it is drawn it will break up inot multi lines. I Know the ascii value is 13 for the carrage return symbol and have tried to use the code to add it into a string. can somebody help me with breaking strings with the carrage return symbol? I thought something like this might work but it didn't: "line 1 Chr(13) Line 2" |
| ||
~n is newline for commands like Print and Notify (e.g. "Line 1~nLine2") but that approach won't work with DrawText. |
| ||
This works: Print "hi"+Chr(10)+"whats up?" But if you use DrawText it will still draw only one line |
| ||
Oh i see. :( I suppose I could create an object that holds a list of lines derrived from a base string. Then the object could simply use a for loop and draw each list index correct? I suppose I need help figuring out how to store the line segments if they exceed a specific pixel based width. so if my string is something like "Hello my dad is a professional Buttoneer and he makes vests for a living" and i have an array called "my_list" and max pixel width of "width%" pixels How do I put sentence fragments into "my_list"? I'm making my own gui system. :) |
| ||
Well, the easiest way would be to run a loop that finds each occurrence of a " " space, trims the word and adds it to a list. Something like this global str$ = "Hello my dad is a professional buttoneer and he makes vests for a living." global strlist:tlist = new tlist global index:int = 1 while(index) str.trim() index = str.find( " ", 0) 'this will be -1 when a space can't be found if(index=-1) strlist.addlast(str[0..]) 'add the last word endif strlist.addlast( str[0..index]) 'add word to list str = str[index..] 'chop the word off the front of the string wend Note: The code above isn't tested, but that's the basic principle. Note, this isn't the fastest or most elegant method, but probably the easiest. When printing the words back out, you can test the length of each word by checking it's length parameter, and if that length plus the length of the previous text is over your max width, you add a newline character, reset your width count, and then start printing again. |
| ||
http://www.blitzbasic.com/codearcs/codearcs.php?code=1374 |
| ||
Thank you! I'll give it a go when I get time. |