I am horrible with regular expressions. I thought that this would be on the easier side, but when I sat down to do to it, I wasn’t able to get it to work and got frustrated and decided I didn’t need to do it, so I threw it away and did something different.
One of my beta testers, however, thought that how I presented the text didn’t look good, so considering going back to this again.
Here is what I need to do. Take a string of text that I retrieve from an XML file and parse it into separate strings. Here is an example of the string:
LINE 1\n|Line 2 will be a long line of text.\n\n|LINE 3\n|Line 4 is another line of text that will appear here.
I wanted to break that into 4 strings – using the | character as the character to break on, but not include the character in the final strings – keeping the line breaks, that I will then create separate text elements of each, so that I can center lines 1 and 3, and left align lines 2 and 4.
It will not be consistently 4 strings. It could be anything from 2-8, most likely. And I can’t break the string up in the XML file (to keep with the node formatting that was already structured).
I use the Text Wrapper component to determine the largest font size that I can use for any given text block, so I will use that string as a whole to get the correct font size, then use the broken up strings as separate text elements with that correct font size, positioned one after the other.
Any suggestions on how to parse such a string, especially not knowing from the outset in the code how many strings you will be creating?
Appreciate any help that anyone can give.