Solved

Text formating

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now