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?
$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?
$myStory =~ s/\n/<BR>/g;
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.
$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.
ASKER
ozo, cool, worked first time,
can never get my head around those search string things!
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
$myStory =~ s/\n/\n<BR>/g;
which will make the source easier to read.
Points go to ozo though. As usual... :-)
Martin
ASKER
martinag,
I already did this ;)))
ozo can you repost as answer
thanks for your help everybody!
I already did this ;)))
ozo can you repost as answer
thanks for your help everybody!
>> ;)))
Are those )s your double chins? ;-)
Martin
Are those )s your double chins? ;-)
Martin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.