in reply to Capturing the nth word in a string
prints "sentence". It seems very complicated, though.$str = "this is a sentence of words and I want the nth one"; $n = 4; # the word we want $a = 0; $a = 1 + index $str, $", $a while --$n; $word = substr $str, $a, -$a + index $str, $", $a; print "$word";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Capturing the nth word in a string
by Jasper (Chaplain) on Oct 14, 2003 at 13:14 UTC |