in reply to Re^3: how to shorten given string?
in thread how to shorten given string?
and it's short enough.s/^(.{1,20}).*/$1/;
Why use a regexp? What if he wants a trailing ellipsis (= 3 dots) in case the string is shortened?
The neat thing about using regexes is that it's easy to modify to make it sing and dance, once the requirements change ever so slightly.s/^(.{1,20})(.+)?/$1 . (defined $2 ? "..." : "")/e;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: how to shorten given string?
by davido (Cardinal) on Oct 14, 2004 at 03:08 UTC | |
by bart (Canon) on Oct 14, 2004 at 03:12 UTC |