On 28/07/2011 14:23, Khabza Mkhize wrote:
I want to substring words, I might be using wrong terminology. But I tried
the following example the only problem I have it cut word any where it
likes. eg "breathtaking" on my string is only bre.
$string = "This is an awe-inspiring tour to the towering headland
known as Cape Point. Magnificent beaches, breathtaking views, historic and
picturesque coastal ";
$rtioverview = substr ( $string , 0 , 100 );
Reults = "This is an awe-inspiring tour to the towering headland known
as Cape Point. Magnificent beaches, bre";
any one can help to solve this problem please?
It depends what you mean by a 'word'. The 'split' operator will split a
string on whitespace, but on that basis there are only twenty words in
your sample string. Take a look at the program below. If it doesn't help
you then please could you give an example showing what result you would
expect from this data?
Cheers,
Rob
use strict;
use warnings;
my $string = "This is an awe-inspiring tour to the towering headland
known as Cape Point. Magnificent beaches, breathtaking views, historic and
picturesque coastal ";
my @words = split ' ', $string;
print scalar @words, " words:\n";
for my $i (0 .. $#words) {
printf "%3d: %s\n", $i, $words[$i];
}
**OUTPUT**
21 words:
0: This
1: is
2: an
3: awe-inspiring
4: tour
5: to
6: the
7: towering
8: headland
9: known
10: as
11: Cape
12: Point.
13: Magnificent
14: beaches,
15: breathtaking
16: views,
17: historic
18: and
19: picturesque
20: coastal
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/