【发布时间】:2013-11-28 04:02:59
【问题描述】:
我需要显示应该显示的数据库中的数据:
in the html: Behälter
in the browser: Behälter
但相反,我得到了这样的数据:
in the html: Behälter
in the browser: Behälter
所以我需要将& 改回&。我使用 Java 的 String 类中的 replaceAll 和 replace 方法。但它没有用。我什至使用 indexOf 方法检查字符串是否有 & ,但它似乎没有捕捉到甚至看到 & 符号。
我的代码:
// supposed the value returned by the getObject function is "Behälter"
String text = (String)getObject("value");
if (text.indexOf("&") >= 0) text = "abc" + text;
text = text.replace("&", "&");
text = text.replaceAll("&", "&");
if (text.indexOf("&") >= 0) text = text + "def";
text = text + "xyz";
结果是
in the html: Behälterxyz
in the browser: Behälterxyz
我输入和使用 replace/replaceAll 的方式有什么问题吗?谢谢你的回答。
【问题讨论】:
-
是的。我想如果替换&符号,浏览器将自动在其 unicode 字符对应物中显示 ä 字符。但是当我查看页面源时,ä 字符仍然写为
ä,而不是ä。
标签: java string replace replaceall