【发布时间】:2014-06-23 06:27:30
【问题描述】:
我正在尝试编写一种方法,将字符串中 html 代码的一些变量替换为例如图片来源等。
String html = "<img src='IMAGE_SOURCE' width='IMAGE_WIDTH' align='IMAGE_ALIGN";
现在这是我的字符串,我已经编写了三个方法:
public void setImageSource(String src) {
html.replace("IMAGE_SOURCE", "Here comes the source for the image");
}
public void setImageWidth(String width) {
html.replace("IMAGE_SOURCE", "Here comes the width for the image");
}
public void setImageAlign(String align) {
html.replace("IMAGE_SOURCE", "Here comes the align for the image");
}
方法被调用,但字符串“html”不会改变。有什么建议吗?
【问题讨论】:
-
字符串是不可变的。