Link to home
Start Free TrialLog in
Avatar of georgep23
georgep23

asked on

string char replacement

I have a variable $myStory that contains text and line breaks eg:

$myStory = "This is the first line\nthis is the second line\nthis is the thrid\n"

notice the line breaks.

I want print the string char by char, if the char is a "\n" I want to print a "<BR>"

I tried to convert all the \n to a <BR>'s with the following code but doesn't work with more that one charater:

$myStory =~ tr/\n/"<BR>"/;

can anybody help me out?
Avatar of ozo
ozo
Flag of United States of America image

$myStory =~ s/\n/<BR>/g;
Avatar of development
development

have you tried
$line=~ s/\\n/<BR>/ig;
The g option on the end is global, so it does more than one in the line.  Ignore the $line, thats me being lazy.
Avatar of georgep23

ASKER

ozo, cool, worked first time,

can never get my head around those search string things!


I'd do
$myStory =~ s/\n/\n<BR>/g;
which will make the source easier to read.

Points go to ozo though. As usual... :-)

Martin
martinag,
I already did this ;)))


ozo can you repost as answer

thanks for your help everybody!
>> ;)))
Are those )s your double chins? ;-)

Martin
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial