string index fucntion

------_=_NextPart_001_01CBBD79.8528B3F7
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi All



There is a sting as : "The cat is sat on the mat" .

I want to get index of second occurrence of "at" using index
function . Can it be possible?



Thanks

Sunita


------_=_NextPart_001_01CBBD79.8528B3F7--
Sunita Rani Pradhan [ Mi, 26 Januar 2011 17:53 ] [ ID #2053883 ]

Re: string index fucntion

On 11-01-26 11:53 AM, Sunita Rani Pradhan wrote:
> There is a sting as : "The cat is sat on the mat" .
>
> I want to get index of second occurrence of "at" using index
> function . Can it be possible?

Yes.

my $second_at = index( $string, 'at', index( $string, 'at' ));


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shawn H Corey [ Mi, 26 Januar 2011 18:13 ] [ ID #2053884 ]

RE: string index fucntion

I think , this is like : index( $string, 'at', index( $string, 'at' ) +
1); Please let me know , if I am wrong.

Thanks
Sunita

-----Original Message-----
From: Shawn H Corey [mailto:shawnhcorey [at] gmail.com]
Sent: Wednesday, January 26, 2011 10:44 PM
To: beginners [at] perl.org
Subject: Re: string index fucntion

On 11-01-26 11:53 AM, Sunita Rani Pradhan wrote:
> There is a sting as : "The cat is sat on the mat" .
>
> I want to get index of second occurrence of "at" using index
> function . Can it be possible?

Yes.

my $second_at =3D index( $string, 'at', index( $string, 'at' ));


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/



--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Sunita Rani Pradhan [ Mi, 26 Januar 2011 19:06 ] [ ID #2053885 ]

Re: string index fucntion

On 11-01-26 01:06 PM, Sunita Rani Pradhan wrote:
> I think , this is like : index( $string, 'at', index( $string, 'at' ) +
> 1); Please let me know , if I am wrong.

I think you are correct.

#!/usr/bin/perl

use strict;
use warnings;

my $string = "The cat is sat on the mat";

for my $i ( 0 .. length( $string )){
printf "% 3d % 3d\t" , $i, index( $string, 'at', $i );
printf "% 3d % 3d\t" , $i, index( $string, 'at', index( $string,
'at', $i ));
printf "% 3d % 3d\t" , $i, index( $string, 'at', index( $string,
'at', $i ) + 1);
print "\n";
}
__END__


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shawn H Corey [ Mi, 26 Januar 2011 19:52 ] [ ID #2053886 ]
Perl » gmane.comp.lang.perl.beginners » string index fucntion

Vorheriges Thema: Newbie queries
Nächstes Thema: array like split of string