For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > November 2006 > case insensitive index function









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author case insensitive index function
Parvinder

2006-11-06, 9:56 pm

index() function is used to match and find the position of a letter or
a substring in a string, how can i do a case insensitive match
like i need to find out "RO" in the given string "Frog"

Thanks in advance for your help
~Parvinde

usenet@DavidFilmer.com

2006-11-06, 9:56 pm

Parvinder wrote:
> a substring in a string, how can i do a case insensitive match
> like i need to find out "RO" in the given string "Frog"


Instead of trying to match case-insensitive, why not match in such a
way that case doesn't matter? You can do that by matching the
uppercased (or lowercased) version of the string, such as:

my $string = 'Frog';
print index (uc $string, 'RO');

(this assumes you always know your match string is uppercase; you may
need to uc() that as well if you cannot be thus assured).

--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com