Posts: 3,324
Threads: 96
Joined: Sep 2013
Example concept code:
Код:
#include <a_samp>
main()
{
new badwords[][] = {"fuck", "bitch"};
new input[] = "fuck you bitch"; // whatever string you want to test
print(input);
for (new i, pos; i < sizeof badwords; i++)
while ((pos = strfind(input, badwords[i], true), pos) != -1)
for (new p; p < strlen(badwords[i]); p++)
input[pos + p] = '*';
print(input);
}
EDIT: Tested, prints "**** you *****".
EDIT EDIT: The following code would censor everything except the first character:
Код:
#include <a_samp>
main()
{
new badwords[][] = {"fuck", "bitch"};
new input[] = "fuck you bitch"; // whatever string you want to test
print(input);
for (new i, pos; i < sizeof badwords; i++)
while ((pos = strfind(input, badwords[i], true), pos) != -1)
for (new p; p < strlen(badwords[i]) - 1; p++)
input[pos + p + 1] = '*';
print(input);
}
Output: "f*** you b*****"
EDIT EDIT EDIT: Added ignore case...
Posts: 1,208
Threads: 36
Joined: Apr 2015
...
PHP код:
new badwords[][] = {"fuck", "bitch"};
public OnPlayerText(playerid, text[]){
for(new i, pos; i < sizeof badwords; i++){
while((pos = strfind(text, badwords[i], true), pos) != -1){
for(new p; p < strlen(badwords[i]) - 1; p++){
text[pos + p + 1] = '*';
}
}
}
//...
return 1;
}
Posts: 3,324
Threads: 96
Joined: Sep 2013
I posted a better one in Useful Functions btw.