Character change to '*' or 'x' - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Character change to '*' or 'x' (
/showthread.php?tid=572613)
Character change to '*' or 'x' -
ToiletDuck - 30.04.2015
I have no idea how can i make characters into "*" or "x" something like that :3 can anyone provide a function or an example? for example i type "toiletduck" and it will automatically replace "xxxxxxx" or "********" it depends how many characters contain in a string
Thanks in Advance!
Re: Character change to '*' or 'x' -
BleverCastard - 30.04.2015
strfind is your friend.
Re: Character change to '*' or 'x' -
Kar - 30.04.2015
Usage:
pawn Код:
strreplace(stringVar, "\\n", "\n", true, .maxlength = 1076);
\\n = what you want to replace.
\n = what you are replacing the above with.
true = ignorecase.
Function:
pawn Код:
stock strreplace(string[], const search[], const replacement[], bool:ignorecase = false, pos = 0, limit = -1, maxlength = sizeof(string)) {
// No need to do anything if the limit is 0.
if (limit == 0) return 0;
new
sublen = strlen(search),
replen = strlen(replacement),
bool:packed = ispacked(string),
maxlen = maxlength,
len = strlen(string),
count = 0
;
// "maxlen" holds the max string length (not to be confused with "maxlength", which holds the max. array size).
// Since packed strings hold 4 characters per array slot, we multiply "maxlen" by 4.
if (packed) maxlen *= 4;
// If the length of the substring is 0, we have nothing to look for..
if (!sublen) return 0;
// In this line we both assign the return value from "strfind" to "pos" then check if it's -1.
while (-1 != (pos = strfind(string, search, ignorecase, pos))) {
// Delete the string we found
strdel(string, pos, pos + sublen);
len -= sublen;
// If there's anything to put as replacement, insert it. Make sure there's enough room first.
if (replen && len + replen < maxlen) {
strins(string, replacement, pos, maxlength);
pos += replen;
len += replen;
}
// Is there a limit of number of replacements, if so, did we break it?
if (limit != -1 && ++count >= limit)
break;
}
return count;
}
Credits to slice.
Re: Character change to '*' or 'x' -
JaKe Elite - 30.04.2015
I did say you could use this.
PHP код:
stock Cenzura(string[], words[], destch = '*')
{
new start_index = (-1),
end_index = (-1);
start_index = strfind(string, words, true);
if(start_index == (-1)) return false;
end_index = (start_index+strlen(words));
for( ; start_index < end_index; start_index++)
string[start_index] = destch;
return true;
}
It replace the word of the specific word string to '*'
Simple usage.
PHP код:
Cenzura(text, "Gay");
This replaces the gay from the chat OnPlayerText to ***, This is a rip of function from JakAdmin3.
- GO PINOY! Read mah location
Re: Character change to '*' or 'x' -
ToiletDuck - 30.04.2015
Quote:
Originally Posted by Kar
Usage:
pawn Код:
strreplace(stringVar, "\\n", "\n", true, .maxlength = 1076);
\\n = what you want to replace.
\n = what you are replacing the above with.
true = ignorecase.
Function:
pawn Код:
stock strreplace(string[], const search[], const replacement[], bool:ignorecase = false, pos = 0, limit = -1, maxlength = sizeof(string)) { // No need to do anything if the limit is 0. if (limit == 0) return 0; new sublen = strlen(search), replen = strlen(replacement), bool:packed = ispacked(string), maxlen = maxlength, len = strlen(string), count = 0 ; // "maxlen" holds the max string length (not to be confused with "maxlength", which holds the max. array size). // Since packed strings hold 4 characters per array slot, we multiply "maxlen" by 4. if (packed) maxlen *= 4;
// If the length of the substring is 0, we have nothing to look for.. if (!sublen) return 0;
// In this line we both assign the return value from "strfind" to "pos" then check if it's -1. while (-1 != (pos = strfind(string, search, ignorecase, pos))) { // Delete the string we found strdel(string, pos, pos + sublen);
len -= sublen;
// If there's anything to put as replacement, insert it. Make sure there's enough room first. if (replen && len + replen < maxlen) { strins(string, replacement, pos, maxlength);
pos += replen; len += replen; }
// Is there a limit of number of replacements, if so, did we break it? if (limit != -1 && ++count >= limit) break; } return count; }
Credits to slice.
|
Quote:
Originally Posted by JaKe Elite
I did say you could use this.
PHP код:
stock Cenzura(string[], words[], destch = '*')
{
new start_index = (-1),
end_index = (-1);
start_index = strfind(string, words, true);
if(start_index == (-1)) return false;
end_index = (start_index+strlen(words));
for( ; start_index < end_index; start_index++)
string[start_index] = destch;
return true;
}
It replace the word of the specific word string to '*'
Simple usage.
PHP код:
Cenzura(text, "Gay");
This replaces the gay from the chat OnPlayerText to ***, This is a rip of function from JakAdmin3.
- GO PINOY! Read mah location
|
Thanks Guys
-Jake Yea Pinoy Rocks xD hahaha wla kasi ako idea paano ko gagawin to :3 gumagwa kasi ako ng kakaibang Login And Register System Using textdraw, slmat!