04.08.2012, 10:34
I've written something for ya:
You can change patterns to some other if you want
Example usage:
Result: Yup, Nope, Nope
(Goto only for sake of getting out of double loop without additional variables)
pawn Code:
stock checker(string[]) {
new valid = true;
new patterns[3][] = {
{ "ABCDEFGHIJKLMNOPRSTUWXYZ" },
{ "abcdefghijklmnoprstuwxyz" },
{ "0123456789" }
};
for(new i = 0; i < sizeof(patterns); i++) {
for(new j = 0; j < strlen(patterns[i]); j++) {
//This is due to something weird with patterns[i][j]
new cchar = patterns[i][j]; //We need char
new sub[2];
format(sub, sizeof(sub), "%s", cchar); //And string again
if(-1 != strfind(string, sub)) break; //Found it!
else {
//Check if last run, if yes, jump out of here to label
if(j == (strlen(patterns[i])-1)) {
valid = false;
goto finish_now;
}
}
}
}
finish_now:
return valid;
}
Example usage:
pawn Code:
new str[5];
str = ((checker("I like 9 pancakes")) ? ("Yup") : ("Nope"));
printf("%s", str);
str = ((checker("I like pancakes")) ? ("Yup") : ("Nope"));
printf("%s", str);
str = ((checker("i like pancakes")) ? ("Yup") : ("Nope"));
printf("%s", str);
(Goto only for sake of getting out of double loop without additional variables)