Solved

Text formating

Posted on 1998-07-26
2
160 Views
Last Modified: 2010-03-05
How do i write a routine that allows me to wrap a long text i have in $txt into smaler parts, no longer than 80 Characters?

The routine will have to find the last space in the string that lies within the allowed line length, and then wrap the line there. Sounds easy, but i don't know how to do it!

So please, some one help me.

Martin.
0
Comment
Question by:freak022398
[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 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 70 total points
ID: 1208796
A routine? Surely you jest! Perl can do it in one line! :-)

The following line will wrap $txt each 80 characters, replacing a spce with \n.

$txt =~ s/(\G.{1,80}) /$1\n/g;

Hope this helps!
0
 

Author Comment

by:freak022398
ID: 1208797
And once again, thanks for a guick answer :)
The procedure think is an old Amiga habit :)

CYA. Martin.

0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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

729 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