This might be a little off the wxWidgets topic, but this is something I
need to generate the strings that I display in my wxWidgets GUI, so ...
What I would like to do is to be able to use the % string formatting but
have 'conditional separators' in the text. I.E. the separators would
only appear if there was text on both sides of them.
For example, consider formatting a person's name. The name consists of
first, middle and last parts. Assume the data is supplied in a
dictionary:
name = {'first': 'Mark', 'middle' : 'E.', 'last': 'Erbaugh'}
I can create an string of the name using:
'%(first)s %(middle)s %(last)s' % name ==> 'Mark E. Erbaugh'
Using the same data, I can create a name in the last, first format:
'%(last)s, %(first)s %(middle)s' % name ==> 'Erbaugh, Mark E.'
Suppose I have a person with no middle name. The resulting string would
have two spaces between the first and last name. Similarly, if the
person only has one name and it was stored in the 'last' field, it would
print with two leading spaces. I'd like the routine to be able to get
rid of these extraneous spaces.
Another use for this would be in formatting of mailing addresses. Some
addresses may have two address lines, some only the first.
addr = {'line1' : '123 XYZ Street', 'line2' : 'Apt 12'}
'%(line1)s\n%(line2)s' % addr
If line2 is blank it would be nice to eliminate the separating '\n', so
there would be no blank line in the address.
Mark