strreplace problem - 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: strreplace problem (
/showthread.php?tid=662775)
strreplace problem -
NoteND - 11.01.2019
Why does this strreplace(path, " ", "_"); give me an error error 035: argument type mismatch (argument 2)
stock strreplace(string[], find, replace)
{
for(new i=0; string[i]; i++)
{
if(string[i] == find)
{
string[i] = replace;
}
}
}
Basically wanna check if there's space and replace it with "_"
Re: strreplace problem -
Macronix - 11.01.2019
Use this:
pawn Код:
stock str_replace(sSearch[], sReplace[], const sSubject[], &iCount = 0)
{
new
iLengthTarget = strlen(sSearch),
iLengthReplace = strlen(sReplace),
iLengthSource = strlen(sSubject),
iItterations = (iLengthSource - iLengthTarget) + 1;
new
sTemp[128],
sReturn[_strlib_med_string];
strcat(sReturn, sSubject, _strlib_med_string);
iCount = 0;
for(new iIndex; iIndex < iItterations; ++iIndex)
{
strmid(sTemp, sReturn, iIndex, (iIndex + iLengthTarget), (iLengthTarget + 1));
if(!strcmp(sTemp, sSearch, false))
{
strdel(sReturn, iIndex, (iIndex + iLengthTarget));
strins(sReturn, sReplace, iIndex, iLengthReplace);
iIndex += iLengthTarget;
iCount++;
}
}
return sReturn;
}
Arguments:
sSearch[]: String to search for
sReplace[]: String to replace with
sSubject[]: Original string
&iCount: How many times 'sSearch' has been replaced. (optional)
Код:
str_replace(" ", "_", path);
Source:
https://sampforum.blast.hk/showthread.php?tid=85697
Re: strreplace problem -
Macronix - 11.01.2019
Of course, my bad, sorry. Edited the post
Guess i was a bit too lazy there, lol.