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!

searching and replacing a new line character

Status
Not open for further replies.

bobbybobbertson

Programmer
Nov 9, 2001
119
US
i have the following string:
$string = "one|two|three\n";

i want to replace the '\n' character with a pipe symbol '|';

for some reason the following does not work.

$string =~ s/\|/\n/;

neither does:

$string =~ s/\|/\\n/;

what do i need to do?
 
Well, you seem to have some things backwards.

Do you want to replace the \n with a |? If so, then your regex needs to look like:

[tt]
$string =~ s/\n/\|/g;
[/tt]

That will replace all occurances of a \n with a |.

Hope this helps.

-Vic vic cherubini
krs-one@cnunited.com
 
Your code

$string =~ s/\|/\\n/;

..looks like you are trying to escape an escaped character.

'\n' can be used literally as in

s/\|/\n/;

and u dont have to escape it.


regards
C





"Brahmaiva satyam"
-Adi Shankara (788-820 AD)
 
thanks vcher..

i'm a moron. its search and replace... not replace and search.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top