hello,
Can anybody tell me how to test a string, unsing jokers;
eg I want to find word which start with "moe" and are 5 characters long!
OR I'd like to find some which end with "t";
thx a lot
!!
string testing
Moderator: General Moderators
I think the StrPos() function will find a substring in a string and will return an integer specifying the position. Now as strings are an array of characters if your substring appears at the start it will return 0.
So when doing an equality check use 3 equal signs so that it evaluates exactly to 0 as an integer, as if the substring is not found it returns false.
$StrPos = StrPos(Haystack,needle);
$LengthMyString = StrLen($MyString);
if (($StrPos===0) and ($LengthMyString==5)){
....
}
You could use StrRPos() to find the last occurrence of 't' and if this is the same as the string length, then you've found strings which end with 't'. Just add this in as an else if to your logic.
Mike
So when doing an equality check use 3 equal signs so that it evaluates exactly to 0 as an integer, as if the substring is not found it returns false.
$StrPos = StrPos(Haystack,needle);
$LengthMyString = StrLen($MyString);
if (($StrPos===0) and ($LengthMyString==5)){
....
}
You could use StrRPos() to find the last occurrence of 't' and if this is the same as the string length, then you've found strings which end with 't'. Just add this in as an else if to your logic.
Mike