in reply to Searching Strings for Characters
The first line removes all multiple spaces and replaces them with a single space. The second line ignores a leading space then capures 50 characters and if a word extends past the 50 word boundary it catches the rest of the word as well. The if/then block removes that last word if the length of the string is over 50 characters. Keep in mind if someone enters 51 (or more) characters in a row with no spaces then $string will have an empty value at the end of this block of code.$string =~ s/^\s+/ /; ($string) = $string =~ /^\s?(.{0,50}\w+)/; if (length $string > 50) { $string =~ s/\w+$//; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Searching Strings for Characters
by Anonymous Monk on Jun 04, 2002 at 04:10 UTC |