"*"for each character in string
#1

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?
Reply
#2

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] = '*';
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)