SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 30/05/2016, 07:35 PM   #1
Kemula
Big Clucker
 
Join Date: Sep 2012
Posts: 98
Reputation: 1
Thumbs up strtolower?

Hello. Is there any include/plugin or function to use like strtolower? I know that tolower is for characters only (read from the SAMP's wiki).

Thank you
Kemula is offline   Reply With Quote
Old 30/05/2016, 07:39 PM   #2
AndreT
Gangsta
 
AndreT's Avatar
 
Join Date: Jul 2011
Posts: 966
Reputation: 414
Default Re: strtolower?

Try to implement the logic yourself. You have to create a function that takes all the characters in string A and applies the function tolower (https://wiki.sa-mp.com/wiki/Tolower) on them, then puts them in string B in the same order.
AndreT is offline   Reply With Quote
Old 30/05/2016, 07:49 PM   #3
zSuYaNw
Godfather
 
zSuYaNw's Avatar
 
Join Date: Apr 2010
Location: Santa Catarina
Posts: 6,840
Reputation: 672
Default Re: strtolower?

PHP Code:
#define strLower(%0) \
                
static ie0strlen(%0); for( ; != e; ++i) %0[i] |= (<< 5)// By zSuYaNw 
how to use
PHP Code:
new ASD[200];
       
ASD "THE BOMB HAS BEEN PLANTED";

strLower(ASD);

printf(ASD); 
Out: the bomb has been planted
zSuYaNw is offline   Reply With Quote
Old 30/05/2016, 09:01 PM   #4
Kemula
Big Clucker
 
Join Date: Sep 2012
Posts: 98
Reputation: 1
Default Respuesta: Re: strtolower?

Quote:
Originally Posted by AndreT View Post
Try to implement the logic yourself. You have to create a function that takes all the characters in string A and applies the function tolower (https://wiki.sa-mp.com/wiki/Tolower) on them, then puts them in string B in the same order.
Yeah! That was my plan B if there is no built-in function. Thank you

Quote:
Originally Posted by zSuYaNw View Post
PHP Code:
#define strLower(%0) \
                
static ie0strlen(%0); for( ; != e; ++i) %0[i] |= (<< 5)// By zSuYaNw 
how to use
PHP Code:
new ASD[200];
       
ASD "THE BOMB HAS BEEN PLANTED";

strLower(ASD);

printf(ASD); 
Out: the bomb has been planted
Thank you for that macro, can you explain it? There are things I've never seen before like |=
Kemula is offline   Reply With Quote
Old 30/05/2016, 10:06 PM   #5
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,067
Reputation: 2660
Default Re: strtolower?

Damn, just write a function. I don't understand this affection for large macros. They're hardly readable and they increase the size of the compiled code because it is copied to every location is is being used rather than being referenced from a single location.

To understand what is happening, refer to a character table, like this one: http://www.asciitable.com/
You will notice that capital letters and lowercase letters are exactly 32 characters apart from each other. Thus, to convert an uppercase letter to a lowercase one, one must only add 32. Conversely, to convert a lowercase letters to an uppercase one, subtract 32. This is what the (1 << 5) boils down to, only in less readable way.

The pipe symbol means bitwise OR, which combines all the set bits in one number with all set bits in another number to form a number that has all bits turned on that are in either number. But in this case a regular addition (+=) might as well have been used.

And then we see that this macro has a huge flaw: it doesn't check for any other characters or punctuation. So if any of those are present they will be garbled up.
__________________
Vince is offline   Reply With Quote
Old 31/05/2016, 01:29 AM   #6
SickAttack
High-roller
 
Join Date: Dec 2013
Posts: 4,761
Reputation: 754
Default Re: strtolower?

pawn Code:
stock CapitalizeString(string[])
{
    for(new i = 0, j = strlen(string); i < j; i ++)
    {
        string[i] = toupper(string[i]);
    }
    return 1;
}

stock UncapitalizeString(string[])
{
    for(new i = 0, j = strlen(string); i < j; i ++)
    {
        string[i] = tolower(string[i]);
    }
    return 1;
}
SickAttack is offline   Reply With Quote
Old 31/05/2016, 02:51 AM   #7
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 1,939
Reputation: 504
Default Re: strtolower?

the difference of ascii value of lower and upper case is 32 where lower case value is greater so using this logic in a loop of an string array u can convert upper to lower and vice versa
SyS is offline   Reply With Quote
Old 31/05/2016, 03:07 AM   #8
SickAttack
High-roller
 
Join Date: Dec 2013
Posts: 4,761
Reputation: 754
Default Re: strtolower?

Quote:
Originally Posted by Sreyas View Post
the difference of ascii value of lower and upper case is 32 where lower case value is greater so using this logic in a loop of an string array u can convert upper to lower and vice versa
Toupper & tolower exist. They avoid that issue.
SickAttack is offline   Reply With Quote
Old 31/05/2016, 03:10 AM   #9
justice96
Guest
 
Posts: n/a
Default Re: strtolower?

Code:
#define strToLower(%0) \
    for(new i; %0[i] != EOS; ++i) \
        %0[i] = ('A' <= %0[i] <= 'Z') ? (%0[i] += 'a' - 'A') : (%0[i])
  Reply With Quote
Old 31/05/2016, 08:02 AM   #10
Kemula
Big Clucker
 
Join Date: Sep 2012
Posts: 98
Reputation: 1
Default Respuesta: Re: strtolower?

Quote:
Originally Posted by Vince View Post
Damn, just write a function. I don't understand this affection for large macros. They're hardly readable and they increase the size of the compiled code because it is copied to every location is is being used rather than being referenced from a single location.

To understand what is happening, refer to a character table, like this one: http://www.asciitable.com/
You will notice that capital letters and lowercase letters are exactly 32 characters apart from each other. Thus, to convert an uppercase letter to a lowercase one, one must only add 32. Conversely, to convert a lowercase letters to an uppercase one, subtract 32. This is what the (1 << 5) boils down to, only in less readable way.

The pipe symbol means bitwise OR, which combines all the set bits in one number with all set bits in another number to form a number that has all bits turned on that are in either number. But in this case a regular addition (+=) might as well have been used.

And then we see that this macro has a huge flaw: it doesn't check for any other characters or punctuation. So if any of those are present they will be garbled up.
Thanks! You've cleared some questions I had.

Thanks everybody
Kemula is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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



All times are GMT. The time now is 09:03 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.