Forum Moderators: coopster

Message Too Old, No Replies

Function to check if string A contains string B

         

globay

3:37 pm on May 18, 2003 (gmt 0)

10+ Year Member



I have a string (ABC) and want to check if another String contains the first one.

Important:
- Lower Case, Upper Case should be regarded as the same.
- String (ABC) for example should be found in String(-§$%abCd)

Does anybody know how to do this?
I coun't find a solution so far.

Help is greatly appreciated.

--
globay

aspr1n

3:51 pm on May 18, 2003 (gmt 0)

10+ Year Member



$needle;  
$haystack;
strstr( $haystack, strtolower( $needle ) );

or
stristr( $haystack, $needle );

asp

ShawnR

4:13 pm on May 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And in perl:

$haystack = '-§$%abCd';
$needle = 'ABC';

$_ = $haystack;
if (/$needle/i) {
# .....
}

Shawn

globay

4:38 pm on May 18, 2003 (gmt 0)

10+ Year Member



Thanks, that works perfectly!