Hi,
the attached patch add support for quotes to the word and words functions. That means, that one can use something like
str = "one 'second word' three"
print word(str, 2)
which prints second word.
See the attached demo file for more test cases, including handling of wrapped quotes and more special cases.
Some more explanations:
The code doesn't recognize escaped quote characters, but e.g. single quotes can be nested inside of double quotested inside of double quotes:
The output is:
Another thing is, that starting quotes are recognized only when they appear at the string start, or after a white space.
The output is:
As closing quote, however, the next matching character is selected:
The output is:
So, the code should handle many practical situations.
I am not so sure this is a good idea.
Doesn't it conflict with processing apostrophes in a normal text string?
And doesn't it conflict with existing processing of text in data files?
E.g.
Yes, I agree that this isn't 100% compatible. But processing of apostrophes is not a problem, your example works fine.
Output is:
Problematic would be if you have an apostrophe at the beginning of a word.
On the other hand, with the current implementation it isn't possible to keep something together which is separated by spaces. With the patch, the follwing works fine:
To avoid problems with apostrophes, one could also think about allowing only double quotes.
I think this is another problem that cries for my old wish "array variables" as ideal solution. ;-)
OK.
Could you please add an update for the documentation?
Hi,
here is an update for the documentation and the stringvar demo. Feel free to correct my english :)
Christoph