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

How do you remove New Line/carraige return from a string?

Status
Not open for further replies.

huckfinn

Programmer
May 19, 2000
4
0
0
US
I've got a string with a New Line/carraige return in it and I'm trying to remove it.&nbsp;&nbsp;I thought it was like this:<br>$TheString=~s/.//s;<br>but I'm incorrect.<br>Does anyone know how to do this?<br><br>Thanks,<br>Huck Finn
 
I think the trim() function trims the whitespace.. I know there's a function that does it. Try trim(). <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
If the newLine/CarriageReturn is at the end of the $str, <br><FONT FACE=monospace>chomp($str);</font><br><br>If the&nbsp;&nbsp;newLine/CarriageReturn is embedded in the $str, <br><FONT FACE=monospace>$str =~ s/\n¦\r//g;</font><br><br>'hope this helps.... <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
think you have to set $*=1 as well so that perl does pattern matching on string with embedded new-line characters <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Your right Mike,.....I left out a switch....<br><br>an alternative to $* =1 is using the 's' switch in a the match.....<br><br><FONT FACE=monospace>$str =~ s/\n¦\r//sg;</font> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
ahhh - &lt;smile&gt; didn't know *that* one -- thx <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top