AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to make a string random character case (https://forums.alliedmods.net/showthread.php?t=210588)

bcKq 03-12-2013 10:28

How to make a string random character case
 
Hello, how I can make a string in a random character case? I mean not that it's 2 options, one is lower case and second is upper, but I want all characters in my string to go random case, like:
this: This is a string
to that: ThIs iS A STRiNG

The string is stored in a variable named "g_TypeWord[128]" (sometimes it's less chars).

Thank you for help ;)

Ef_Deas 03-12-2013 11:06

Re: How to make a string random character case
 
PHP Code:

for(new ii<charsmax(g_TypeWord); i++)
g_TypeWord[i] = random_num(0,1) ? toupperg_TypeWord[i] ) : tolowerg_TypeWord[i] ); 


^SmileY 03-12-2013 13:26

Re: How to make a string random character case
 
charsmax(g_TypeWord) ?? not sizeof(g_TypeWord) ???

PHP Code:

for(new i;sizeof(g_TypeWord);i++)
g_TypeWord[i] = random_num(0,1) ? toupperg_TypeWord[i] ) : tolowerg_TypeWord[i] ); 


Backstabnoob 03-12-2013 13:48

Re: How to make a string random character case
 
Neither of these, use strlen.

Also, it would be better to use two constant arrays, one with uppercase symbols and one with lowercase, then change them.

^SmileY 03-12-2013 13:50

Re: How to make a string random character case
 
Yeah Yeah, considering if a somenone not using a g_TypeWord[128] chars size;

Work anyway

Backstabnoob 03-12-2013 13:51

Re: How to make a string random character case
 
What? If there's a string of 60 characters in 128 cell array, you will waste a lot of memory because you will be calling a native another 68 times for nothing.

It doesn't matter if it works, strlen should be used here no matter what.

micapat 03-12-2013 14:01

Re: How to make a string random character case
 
PHP Code:

for( g_TypeWord] ; i++ )
{




bcKq 03-15-2013 19:35

Re: How to make a string random character case
 
This:
PHP Code:

new len;
read_file(g_TypeDirrandom(file_size(g_TypeDir1)), g_TypeWord127len);
for(new 
istrlen(g_TypeWord); i++)
{
    
g_TypeWord[i] = random_num(0,1) ? toupperg_TypeWord[i] ) : tolowerg_TypeWord[i] );


Works perfect. I've got much function calls so I used strlen to save as much memory as I can.
Thank you everyone.


All times are GMT -4. The time now is 21:47.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.