I'll add some more features to this function and publish somewhere so others can use it too
Let's go piece by piece:
pawn Code:
new valid = true;
new patterns[3][] = {
{ "ABCDEFGHIJKLMNOPRSTUWXYZ" },
{ "abcdefghijklmnoprstuwxyz" },
{ "0123456789" }
};
Before we start, we assume the string is valid. Next we define patterns - the string has to contain at least one character of each pattern. You can define your own, like "A4G.?" - the string can only be vaild if it contains A, 4, G, . or ? (assuming there are no other patterns).
pawn Code:
for(new i = 0; i < sizeof(patterns); i++) {
for(new j = 0; j < strlen(patterns[i]); j++) { /* (...) */ }
}
finish_now:
Now we loop through each pattern, and each character in each pattern
pawn Code:
new cchar = patterns[i][j]; //We need char
new sub[2];
format(sub, sizeof(sub), "%s", cchar);
This a little hacky, we need simple example
pawn Code:
new string[6] = "Hello";
printf("%s", string[2]);
I expected this to print single character at position 3, but nope. It will print piece of string
from the character at 3 position
If you want single char you need
pawn Code:
printf("%c", string[2]);
//to store in variable:
new singlechar = string[2];
I needed string so I used format (now I think strmid would be better solution). Anyway
pawn Code:
if(-1 != strfind(string, sub)) break;
If character from current pattern is present in string - go and check next pattern
pawn Code:
else {
if(j == (strlen(patterns[i])-1)) {
valid = false;
goto finish_now;
}
}
The character in current set was not found, and we are on last iteration. The string is now invalid. Check valid as false, and jump out of both loops, because we don't care about other patterns now.
Return valid variable
@Up: Hey, I had idea how to do this that way, don't blame me :c Also you can change your solution to not check strcmp on each loop iteration