Raised This Month: $ Target: $400
 0% 

How to make a string random character case


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bcKq
Member
Join Date: Dec 2012
Location: Tczew, Poland
Old 03-12-2013 , 10:28   How to make a string random character case
Reply With Quote #1

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 ;)
bcKq is offline
Ef_Deas
Member
Join Date: Aug 2012
Location: Rio de Janeiro
Old 03-12-2013 , 11:06   Re: How to make a string random character case
Reply With Quote #2

PHP Code:
for(new ii<charsmax(g_TypeWord); i++)
g_TypeWord[i] = random_num(0,1) ? toupperg_TypeWord[i] ) : tolowerg_TypeWord[i] ); 
Ef_Deas is offline
Send a message via Skype™ to Ef_Deas
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 03-12-2013 , 13:26   Re: How to make a string random character case
Reply With Quote #3

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] ); 
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 03-12-2013 , 13:48   Re: How to make a string random character case
Reply With Quote #4

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.

Last edited by Backstabnoob; 03-12-2013 at 13:50.
Backstabnoob is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 03-12-2013 , 13:50   Re: How to make a string random character case
Reply With Quote #5

Yeah Yeah, considering if a somenone not using a g_TypeWord[128] chars size;

Work anyway
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 03-12-2013 , 13:51   Re: How to make a string random character case
Reply With Quote #6

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.

Last edited by Backstabnoob; 03-12-2013 at 13:53.
Backstabnoob is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 03-12-2013 , 14:01   Re: How to make a string random character case
Reply With Quote #7

PHP Code:
for( g_TypeWord] ; i++ )
{


__________________
micapat is offline
Old 03-12-2013, 14:45
hleV
This message has been deleted by hleV.
bcKq
Member
Join Date: Dec 2012
Location: Tczew, Poland
Old 03-15-2013 , 19:35   Re: How to make a string random character case
Reply With Quote #8

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.
bcKq is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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