Quote:
Originally Posted by Misiur
I've written something for ya:
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; }
You can change patterns to some other if you want
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);
Result: Yup, Nope, Nope
(Goto only for sake of getting out of double loop without additional variables)
|
Brother if you can explain the code to me a little more , ill appreciate a lot. Im bad at strings as i bunked every class at my college.
I mean can you change it a bit to return 1 and o if true or false. If the string contains an Upper Case, Lower Case and a Number , it will return true(1) else false(0).
And simplify it a bit with elaboration?
(Rep+6 Added)