strtolower?
#1

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

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://sampwiki.blast.hk/wiki/Tolower) on them, then puts them in string B in the same order.
Reply
#3

PHP код:
#define strLower(%0) \
                
static ie0strlen(%0); for( ; != e; ++i) %0[i] |= (<< 5)// By zSuYaNw 
how to use
PHP код:
new ASD[200];
       
ASD "THE BOMB HAS BEEN PLANTED";
strLower(ASD);
printf(ASD); 
Out: the bomb has been planted
Reply
#4

Quote:
Originally Posted by AndreT
Посмотреть сообщение
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://sampwiki.blast.hk/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
Посмотреть сообщение
PHP код:
#define strLower(%0) \
                
static ie0strlen(%0); for( ; != e; ++i) %0[i] |= (<< 5)// By zSuYaNw 
how to use
PHP код:
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 |=
Reply
#5

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.
Reply
#6

pawn Код:
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;
}
Reply
#7

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
Reply
#8

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
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.
Reply
#9

Код:
#define strToLower(%0) \
    for(new i; %0[i] != EOS; ++i) \
        %0[i] = ('A' <= %0[i] <= 'Z') ? (%0[i] += 'a' - 'A') : (%0[i])
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)