Mr Man
Mr Man

Reputation: 1588

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 instance:

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.

Upvotes: 1

Views: 184

Answers (2)

Premraj
Premraj

Reputation: 7902

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

Upvotes: 1

dogbane
dogbane

Reputation: 274612

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

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

Upvotes: 2

Related Questions