in reply to Smart Substrings
Only one match needed.
if (length($string) > 15) { $string =~ s/^(.{0,12})\b\s.*/$1.../gi; }
cLive ;-)
Update:
MeowChow pointed out typo - missed out .* (had it on other machine running demo :)
Actually, if there's a chance that the first word will be longer than 15 chars, you'd need to expand this a bit to cut off the end of the first word. Oh hell, let's change a few things here:
if (length($string) > 15) { unless ($string =~ s/^(.{0,12})\b\s.*/$1.../gi) { $string = substr ($string, 0, 12) . '...'; } }
Finally, I disagree with MeowChow (below). I think \b *is* needed. Otherwise this could happen:
A Satsuma - Orange would become A Satsuma -... </CODE>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Smart Substrings
by MeowChow (Vicar) on Apr 03, 2001 at 05:49 UTC |