Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax Question regarding carriage returns?

Status
Not open for further replies.

starblood

Technical User
Feb 28, 2001
63
GB
I have a line of code that replaces <br> tags with the word hello in some copy:

NewValue=whichfield.value.replace(/<br>/gi, "hello");

What I would like is for the <br> tags to be replaced with a carriage return instead. Can't seem to find the right syntax.

The code if for an Intranet, so no cross-browser worries. Anyone give me a clue?
 
All viable in appearance and used in different languages.
[tt]
NewValue=whichfield.value.replace(/<br>/gi, "\r");
or
NewValue=whichfield.value.replace(/<br>/gi, "\n");
or
NewValue=whichfield.value.replace(/<br>/gi, "\r\n");
[/tt]


 
use "\n" for you replace string.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Thank-you tsuji and tsdragon - works perfectly.

Would you believe I tried those options - but without the inverted commas (typical!).

Much appreciation!
 
What in the world is an "inverted comma"?

tsuji: looks like we posted at the same time.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 

An inverted comma is a quotation mark, like an apostrophe.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
a quotation mark, like an apostrophe"

Those are two VERY different animals! Syntactically they work differently. I don't think escape sequences work inside apostrophes like they do in quotes.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
tsdragon said:
I don't think escape sequences work inside apostrophes like they do in quotes.

They work fine, AFAIK. For example, the following two are identical:

Code:
var someVar = 'abc\ndef';

Code:
var someVar = "abc\ndef";

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Maybe it's PERL where literals in apostrophes are not evaluated for escape sequences. It's difficult to keep all the details of syntax straight when you program in so many different languages. It's still a good idea not to confuse the two though. If you're doing asp programming along with your JavaScript it's easy to mess up. VBS uses apostrophes for comments unless their in a " quoted string.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top