03-07-2013 04:50 AM
Hi,
I am trying fit user generated text strings on to a 6*12 display so I have to read in what the user typed and then format it for the display for e.g
'Totally random text string'
Totally/s/s/s/s/s = 7+5 spaces=12
6+6 spaces
Random/s/s/s/s/s/s/s
11+1 space
text string/s
Has anyone done this before or something similar so I can get my head around the concept? Thanks
Solved! Go to Solution.
03-07-2013 05:52 AM
03-07-2013 08:17 AM
I think this is more what OP was looking for. 🙂
/Y
03-07-2013 08:25 AM
Hi Guys,
Thanks for the replies yes Ger its a bit more complex than that..
Yamaeda I cant open that vi due to running 8.5..
When reading the words in decision needs to be made about the next word..will it fit in the 12chars with another word or must it be padded..As the input is entered by the user its varaible but I could limit to no words larger than 12 chars
Heres what I have so far attached
03-07-2013 08:47 AM
Yamaeda's VI saved for LV 8.5
03-07-2013 09:19 AM
Ah brillant stuff ..I would have got there myself in about 10 years..lol.
Thanks everyone!
03-07-2013 09:46 AM
Please mark the solution post. 🙂
/Y
03-07-2013 11:38 AM
Simple greedy word wrap seems like something regexable.
03-08-2013 06:25 PM
Man, Regexp is really hard to decipher. 🙂
/Y
03-08-2013 07:14 PM
Could still be some corner cases since I kind of wrote this literally.
(.{1,%d})( +|$\\n?)|(.{1,%1$d})
consists of three capturing groups, the match is either the first two OR the third one
first: (.{1,N}) The %d is replaced with the width so this captures from 1 to N characters which are not newlines
second : ( +|$\n?) [extra \ is from string display] capture 1 or more spaces (there is a space before the +) OR end of the line with optional newline. Had to make newline optional to handle 1 line strings such as this one. (that is a hard one to catch at first)
third: (.{1,N}) grab the first N non-newline characters
First choice is to match 1 to N characters which are followed by spaces, the end of the string or newline. This is greedy so it gets the longest possible match.
If the first choice fails, you simply grab the first N characters
Replace: Here is another one of my favorite tricks. There are two capture groups we care about either #1 or #3. One will match, the other is empty and we want to replace with the one that matched. If you replace one followed by the other ($1$3) then either way you get the string that matched. Simply add a newline to do the word wrapping. Hard part is to remember to start counting at 1.