in reply to Re^2: Breaking String
in thread Breaking String
for this i have remove lines greater than 2 in $textTo extract just 2 lines, you can do $top2 = $text =~ /^(.*\n.*\n)/;
You can avoid unnecessary work in Text::Wrap if you limit the string you submit to it to a bit over the absolute maximum length of 2 lines together (your text says 140 characters, indeed a bit over 2x60 + 2 for the newlines), because the rest will be cut off anyway.
my $smstext = "This sentence will have more than 120 characters and i +want to truncate this string into two lines containing 60 characters +each and ignore characters above 140 in length" ; use Text::Wrap; local $Text::Wrap::columns = 60; my($text) = wrap('', '', substr($smstext, 0, 140)) =~ /^(.*\n.*\n)/; print $text; __END__ Output: This sentence will have more than 120 characters and i want to truncate this string into two lines containing 60
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Breaking String
by Anonymous Monk on Oct 17, 2008 at 09:25 UTC | |
by Your Mother (Archbishop) on Oct 17, 2008 at 16:00 UTC | |
by bart (Canon) on Oct 18, 2008 at 10:15 UTC |