hii,
ihave a large string that needs to be formated to html format.
now before every chart its like this
-0-
*T
text -----
*T
i need to add <pre> and </pre> tags to replace the *T's but i don't
know how to go about this.
this is the code i used to scan the file an add links
data_body = data_body.replaceAll("((https?|ftp)://|mailto:)[^\\s<]+",
"<A TARGET=\"_new\" HREF=\"$0\">$0</a>");
if anyone knows how to surround the text in <pre> tags please let me
know
thanks.
morc
Oliver Wong - 19 Jan 2006 17:24 GMT
> hii,
> ihave a large string that needs to be formated to html format.
[quoted text clipped - 15 lines]
> if anyone knows how to surround the text in <pre> tags please let me
> know
You need to ensure that the <pre> and </pre> balance out. AFAIK, <pre>
tags cannot be nested within each other.
Replace the first occurence of "*T" you see in your string with "<pre>".
The "first" occurence is now gone, and what was your nth occurence is now
your nth-1 occurence.
Replace the first occurence of "*T" you see in your string with "</pre>".
Ditto.
Replace the first occurence of "*T" you see in your string with "<pre>".
And so on.
- Oliver
questionmarc420@msn.com - 19 Jan 2006 17:35 GMT
thanks but i don't know how to do that. that was my question.
i don't know how to flag the second occurence. ive been using
.replaceAll method because the text is all one string.
Oliver Wong - 19 Jan 2006 17:51 GMT
> thanks but i don't know how to do that. that was my question.
> i don't know how to flag the second occurence. ive been using
> .replaceAll method because the text is all one string.
Isn't there a "replaceFirst" method that you could use instead?
- Oliver
questionmarc420@msn.com - 19 Jan 2006 17:59 GMT
yes. slipped my mind. too mcuh work
thanks alot i've figured out my problem
-morc
Alan Krueger - 19 Jan 2006 23:47 GMT
> -0-
> *T
[quoted text clipped - 7 lines]
> data_body = data_body.replaceAll("((https?|ftp)://|mailto:)[^\\s<]+",
> "<A TARGET=\"_new\" HREF=\"$0\">$0</a>");
This code:
String text = "This is a test.\n" +
"*T\n" +
"Preformatted. * star test\n" +
"*T\n" +
"Not.\n" +
"*T\n" +
"Again!\n" +
"*T\n" +
"Normal.";
text = text.replaceAll( "[*]T(([^*]|[*][^T])*)[*]T",
"<pre>$1</pre>" );
System.out.println( text );
Produces this result:
This is a test.
<pre>
Preformatted. * star test
</pre>
Not.
<pre>
Again!
</pre>
Normal.
This ensures proper grouping of <pre></pre> elements by capturing both
*T occurrences, the start and end, at the same time.