[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: converting html special characters
- To: <ajug-members@ajug.org>
- Subject: RE: converting html special characters
- From: "Lance England" <lengland@gr.com>
- Date: Sat, 4 Aug 2001 18:02:17 -0500
- Cc: <dpardue@dspin.com>
- Thread-Index: AcEcY+nln8W9xsaXQnuiR8Kr4iXhzgA0zdyP
- Thread-Topic: converting html special characters
No, this is not what she needs. URLEncoder does NOT convert a
String into HTML escape characters. URLEncoder makes a String URL-safe,
which means converting spaces into '+', etc.
You actually need to write your own method. Han Bergsten did this in his
great book "JavaServer Pages" (O'Reilly 2001). He wrote a class called
StringFormat that had many methods, including the following:
public static String toHTMLString(String in) {
StringBuffer out = new StringBuffer();
for (int i = 0; in != null && i < in.length(); i++) {
char c = in.charAt(i);
if (c == '\'') {
out.append("'");
}
else if (c == '\"') {
out.append(""");
}
else if (c == '<') {
out.append("<");
}
else if (c == '>') {
out.append(">");
}
else if (c == '&') {
out.append("&");
}
else {
out.append(c);
}
}
return out.toString();
}
I hope this helps!
Lance England
www.gr.com
-----Original Message-----
From: Kenneth.Wills@equifax.com
Sent: Fri 8/3/2001 5:13 PM
To: Deron Pardue
Cc: ajug-members@ajug.org
Subject: Re: converting html special characters
Try java.net.URLEncoder
"Deron
Pardue" To: <ajug-members@ajug.org>
<dpardue@dspi cc:
n.com> Subject: converting html special characters
08/03/01
04:58 PM
Please
respond to
"Deron
Pardue"
Are there any classes that are useful in converting special html
characters to their escape sequences...
For instance to translate
He wrote, " x > 5
into
He wrote, " x > 5 "
Thanks!!!