• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

Text formating

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
freak022398
Asked:
freak022398
1 Solution
 
alamoCommented:
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
 
freak022398Author Commented:
And once again, thanks for a guick answer :)
The procedure think is an old Amiga habit :)

CYA. Martin.

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now