Excluding capital Is and lower Ls from a 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: Excluding capital Is and lower Ls from a string (
/showthread.php?tid=637188)
Excluding capital Is and lower Ls from a string -
Amit1998 - 10.07.2017
Hi,
I'm using Ryder's random string generator and there's a slight confusion when it adds up a capital I or a lower L so I tried adjusting it in order to exclude these from the string but it didn't work:
Код:
stock randomString(strDest[], strLen = 11)
{
new letter[1];
while(strLen--)
{
letter[0] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
while(!strcmp(letter[0], "I", false) || !strcmp(letter[0], "l", false))
{
letter[0] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
}
strDest[strLen] = letter[0];
}
}
What could be the problem? Thanks.
Re: Excluding capital Is and lower Ls from a string -
Kaperstone - 10.07.2017
*deleted*
Re: Excluding capital Is and lower Ls from a string -
OneDay - 10.07.2017
PHP код:
stock randomString(strDest[], strLen = 11)
{
new letter;
while(strLen--)
{
letter = random(2) ? (random(25) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
if (letter == 'I')
letter = 'Z';
else if (letter == 'l')
letter = 'z';
strDest[strLen] = letter;
}
}
Generates less letters and swaps some.
Re: Excluding capital Is and lower Ls from a string -
NaS - 10.07.2017
Why do you use strcmp for comparing one letter?
Just do
Код:
if(letter[0] == 'I' || letter[0] == 'l')
You could also use a do while loop instead of using the same instruction twice:
Код:
do
{
letter[0] = random(2) ? (random(26) + (random(2) ? 'a' : 'A')) : (random(10) + '0');
} while(letter[0] == 'I' || letter[0] == 'l');
Other than that it should work.
EDIT: Oops too late.