Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

string char replacement

Posted on 1998-10-20
7
Medium Priority
?
230 Views
Last Modified: 2010-03-05
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?
0
Comment
Question by:georgep23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1205530
$myStory =~ s/\n/<BR>/g;
0
 
LVL 1

Expert Comment

by:development
ID: 1205531
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.
0
 
LVL 1

Author Comment

by:georgep23
ID: 1205532
ozo, cool, worked first time,

can never get my head around those search string things!


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Expert Comment

by:martinag
ID: 1205533
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
0
 
LVL 1

Author Comment

by:georgep23
ID: 1205534
martinag,
I already did this ;)))


ozo can you repost as answer

thanks for your help everybody!
0
 
LVL 4

Expert Comment

by:martinag
ID: 1205535
>> ;)))
Are those )s your double chins? ;-)

Martin
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 1205536
$myStory =~ s/\n/<BR>\n/g;
# see
# perldoc perlre
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question