SA-MP Forums Archive
"*"for each character in string - 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: "*"for each character in string (/showthread.php?tid=558540)



"*"for each character in string - yellow - 17.01.2015

Hey,

i want to add a "*" for each letter a string has.

"SAMP" -> 4 -> "****"
I actually could do sth like:
Код:
new str[128];
		new a = 0;
		while(a <= strlen(inputtext))
		{
		    strcat(string,"*");
		    a++
		}
Would that work? Or is there a better way to do this?


Re: "*"for each character in string - Vince - 17.01.2015

Loops: if you know the exact amount use for(), otherwise use while(). You know the exact amount (strlen) so you use for() instead. Actually your topic title already reflected it ("for each"), although Pawn does not have a foreach construct.

pawn Код:
for(new i, j = strlen(string); i < j; i++)
{
    string[i] = '*';
}