|
|
| Perl: the Markov chain saw | |
| PerlMonks |
Re: In search of a better way to trim string lengthby davido (Bishop) |
| on Jul 19, 2004 at 08:26 UTC ( #375488=note: print w/ replies, xml ) | Need Help?? |
|
This snippet uses a pure regexp approach to breaking a string up into stringlets of no more than 'n' length, broken on the first whitespace before 'n', OR a hard break at 'n' characters if there is no preceeding whitespace on which to break. Not sure if this is what you're after, but it seems to be a start in the right direction. If you simply want to crop at 'n' or less (depending on whitespace), remove the /g modifier and capture only the first stringlet.
Applying the "..." elipses is trivial at this point. I hope this helps... it's late, I may have misread the question. ;) Dave
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||