30.05.2016, 19:35
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
Thank you

#define strLower(%0) \
static i, e; i = 0, e = strlen(%0); for( ; i != e; ++i) %0[i] |= (1 << 5)// By zSuYaNw
new ASD[200];
ASD = "THE BOMB HAS BEEN PLANTED";
strLower(ASD);
printf(ASD);
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.
|
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;
}
#define strToLower(%0) \ for(new i; %0[i] != EOS; ++i) \ %0[i] = ('A' <= %0[i] <= 'Z') ? (%0[i] += 'a' - 'A') : (%0[i])
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. |