Solved

Text formating

Posted on 1998-07-26
2
155 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

839 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