04.08.2012, 11:16
I'll add some more features to this function and publish somewhere so others can use it too ![Cheesy](images/smilies/biggrin.png)
Let's go piece by piece:
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).
Now we loop through each pattern, and each character in each pattern
This a little hacky, we need simple example
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
I needed string so I used format (now I think strmid would be better solution). Anyway
If character from current pattern is present in string - go and check next pattern
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
![Cheesy](images/smilies/biggrin.png)
Let's go piece by piece:
pawn Code:
new valid = true;
new patterns[3][] = {
{ "ABCDEFGHIJKLMNOPRSTUWXYZ" },
{ "abcdefghijklmnoprstuwxyz" },
{ "0123456789" }
};
pawn Code:
for(new i = 0; i < sizeof(patterns); i++) {
for(new j = 0; j < strlen(patterns[i]); j++) { /* (...) */ }
}
finish_now:
pawn Code:
new cchar = patterns[i][j]; //We need char
new sub[2];
format(sub, sizeof(sub), "%s", cchar);
pawn Code:
new string[6] = "Hello";
printf("%s", string[2]);
Quote:
llo |
pawn Code:
printf("%c", string[2]);
//to store in variable:
new singlechar = string[2];
pawn Code:
if(-1 != strfind(string, sub)) break;
pawn Code:
else {
if(j == (strlen(patterns[i])-1)) {
valid = false;
goto finish_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