hello mylist liststart:1.one 2.this is point two 3.and here we have point three 4.whatever12345 5.:-) end:listend rest of the line
into some valid html code (html list). when im finished it should look like this:
<ol start="1" type="1"> <li>one</li> <li>this is point two</li> <li>and here we have point three</li> <li>whatever12345</li> <li>:-)</li> </ol>
here is what i have so far:
but this code doenst work correctly. anyone any idea?
thanks in advance :-)
Michael Duffy
Ranch Hand
Joined: Oct 15, 2005
Posts: 163
posted
0
Originally posted by Katja Ernst: hi, im trying to convert a string like this
hello mylist liststart:1.one 2.this is point two 3.and here we have point three 4.whatever12345 5.:-) end:listend rest of the line
into some valid html code (html list). when im finished it should look like this:
<ol start="1" type="1"> <li>one</li> <li>this is point two</li> <li>and here we have point three</li> <li>whatever12345</li> <li>:-)</li> </ol>
here is what i have so far:
but this code doenst work correctly. anyone any idea?
thanks in advance :-)
Hi Katja,
I wouldn't do this with a regular expression. I think it's better handled by a parser class that would take a String input and turn it into the appropriate tokens. I'd have a toXML() method that would return the tokens as the XML stream that you want: liststart, liststart, and a delimited string in-between. Choose the delimiter carefully - "dot" might not be the best choice if any of the data can sensibly contain a period.
%
Alan Moore
Ranch Hand
Joined: May 06, 2004
Posts: 262
posted
0
Try this:
Katja Ernst
Greenhorn
Joined: Dec 30, 2005
Posts: 12
posted
0
hi, thanks to both of you.
@alan: your version will not put the last point (5. ...) into <li></li>. what must i do to correct this?
thanks :-)
Alan Moore
Ranch Hand
Joined: May 06, 2004
Posts: 262
posted
0
It works for me, but the regex does assume there's exactly one space character following each list entry. Maybe you need something more flexible:
Katja Ernst
Greenhorn
Joined: Dec 30, 2005
Posts: 12
posted
0
hi, thanks. if i use a line like this one here:
String s = "hello list liststart:1.:-) 2.yyy two 3.dsdsds 4.ttt 5.five:listend and end of the string.";
the output is:
hello list <ol start=1 type=1><li>:-)</li> <li>yyy two</li> <li>dsdsds</li> <li>ttt</li> 5.five</ol> and end of the string.
but should be:
hello list <ol start=1 type=1><li>:-)</li> <li>yyy two</li> <li>dsdsds</li> <li>ttt</li> <li>five</li></ol> and end of the string.
any ideas?
Alan Moore
Ranch Hand
Joined: May 06, 2004
Posts: 262
posted
0
The problem is that you changed the ending delimiter without telling me (but I agree that that "end" token didn't need to be there). Try this:
Katja Ernst
Greenhorn
Joined: Dec 30, 2005
Posts: 12
posted
0
hi, thanks :-D....works as it should! the end delimiter was no delimiter, it was just a word :-)...