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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing new line (\n)

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
Does anybody know how to remove a new line character (\n) from a text string?<br><br>I tried using this:<br><br><i>//gets the html string from the div<br>var str=document.all.theTable.innerHTML;<br><br>//makes sure the loop runs once, and declare tempstr<br>var loop=true,tempstr='';<br><br>//the while loop<br>while (loop){<br><br>//if the string has an end of line character<br>if (str.indexOf('\n')!=-1){<br><br>//store everything before the eol into the tempstr variable<br>tempstr=str.substring(0,str.indexOf('\n'));<br><br>//add everything after the eol to the tempstr variable<br>tempstr+=str.substring(str.indexOf('\n')+1,str.length);<br><br>//write the tempstr to the string, so it can be checked<br>str=tempstr;<br><br>//if the string does not have an end of line character,<br>//don't run the loop again.<br><br>} else loop=false;<br>}<br></i><br><br><br>but for some reason that dosn't work, any ideas? <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
<br>var str = document.all.theTable.innerHTML;<br>var tempstr = str.replace(&quot;\n&quot;,&quot;&quot;);<br> <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
Thanks, but I'm coming back to tell you all that I figured something out!<br><br>however, it is simmilar to nick bulka's suggestion:<br><i>var reg=/(\r)¦(\n)/g<br>str=str.replace(reg,'');</i><br><br>this uses regular expressions to eliminate all of the carrage returns, and the next line characters.<br><br>for more on reular expressions, go where I did:<br><A HREF=" TARGET="_new"> <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top