开发者

replacing a string with an HTML element

I have a string that I want to replace the 'xx' with a line break. I am writing this in a jsp page, just fyi. So for in开发者_如何转开发stance:

tmpString1 = "hello, how are youxxnice to meet you"
string1 = tmpString1.replace('xx', '<br />');

That explains what I would like to do. but I get an unclosed character literal error on this attempt, I have also tried:

tmpString1 = "hello, how are youxxnice to meet you"
string1 = tmpString1.replace('xx', '/n');

And this way it just replaces the 'xx' with a space, I know this seems trivial, but I cant seem to get it working. Thanks for the help.


Use double-quotes for strings. Single-quotes are for chars.

string1 = tmpString1.replace("xx", "<br />");


It should be -

tmpString1 = "hello, how are youxxnice to meet you";
string1 = tmpString1.replace("xx", "<br />");

Note the double quotes for parameters in replace method, as these is not character but String

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜