tolower output
#1

Ok so i have
PHP Code:
    new
        
username[MAX_PLAYER_NAME]
    ;
    
GetPlayerName(playeridusernamesizeof(username)); 
I need to tolower but i dont think im doing it right, Im a PHP guy

I do:
PHP Code:
username tolower(username); 
But its not right, everything i try is wrong. can anyone help me with this ?
Reply
#2

Tolower works with character , you have to set each character of username tolower case separately : LIKE :

pawn Code:
for(new i = 0;i < sizeof(username);i++)
{
username[i] =  tolower(username[0]);
}
For detain see here
https://sampwiki.blast.hk/wiki/Tolower
Reply
#3

Is that really the only way ?
in PHP i wouldnt think of doing that
Reply
#4

Quote:
Originally Posted by Shabi RoxX
View Post
Tolower works with character , you have to set each character of username tolower case separately : LIKE :

pawn Code:
for(new i = 0;i < sizeof(username);i++)
{
username[i] =  tolower(username[0]);
}
For detain see here
https://sampwiki.blast.hk/wiki/Tolower
I tested it and it didnt work
Reply
#5

Quote:
Originally Posted by Dotayuri
View Post
Is that really the only way ?
in PHP i wouldnt think of doing that
You can create you own define function for string by using that function
Reply
#6

Quote:
Originally Posted by Dotayuri
View Post
Is that really the only way ?
in PHP i wouldnt think of doing that
Well yeah it's the way, the aforementioned function works with characters, not with strings.

edit: use username[i] = tolower(username[i])
Reply
#7

try this,
PHP Code:
    new username[MAX_PLAYER_NAME];
    
GetPlayerName(playeridusernamesizeof(username));
    for(new 
0<= 24i++)
    {
        
username[i] =  tolower(username[i]);
    } 
Reply
#8

Hi
pawn Code:
stock xToLower(string[])
{
new output[128];
if(strlen(string) > 128)
{
print("Input is too long! Max: 128 signs");
return 1;
}

for(new char = 0; char < strlen(string); char++)
{
format(output, 128, "%s%c", output, tolower(string[char]));
}
return output;
}
Maybe this?
Usage:
pawn Code:
xToLower(string[]);
Example:
pawn Code:
new String[12];
format(String, 12, "aCAUiFIUA");
printf("%s",xToLower(String));
Greetz,
LetsOWN
Reply
#9

Quote:
Originally Posted by LetsOWN[PL]
View Post
Hi
pawn Code:
stock xToLower(string[])
{
new output[128];
if(strlen(string) > 128)
{
print("Input is too long! Max: 128 signs");
return 1;
}

for(new char = 0; char < strlen(string); char++)
{
format(output, 128, "%s%c", output, tolower(string[char]));
}
return output;
}
Maybe this?
Usage:
pawn Code:
xToLower(string[]);
Example:
pawn Code:
new String[12];
format(String, 12, "aCAUiFIUA");
printf("%s",xToLower(String));
Greetz,
LetsOWN
Ok i think your about to help me skip a few levels on GTA editing
....
Your saying that i make a .pwn in /pawno
and put xToLower in it

then #include <xToLower_File>


and just use it
PHP Code:
new String[12];
format(String12"aCAUiFIUA");
printf("%s",xToLower(String));
And 
i could just do that for any functions i need 
Reply
#10

For your first post

pawn Код:
LowerCase(string[MAX_PLAYER_NAME])
{
    for(new d = strlen(string)-1; d >= 0; d--)
        string[d] = tolower(string[d]);

    return string;
}

    new
        username[MAX_PLAYER_NAME]
    ;

    GetPlayerName(playerid, username, sizeof(username));
    username = LowerCase(username);
Reply
#11

Quote:
Originally Posted by LetsOWN[PL]
View Post
Hi
pawn Code:
stock xToLower(string[])
{
new output[128];
if(strlen(string) > 128)
{
print("Input is too long! Max: 128 signs");
return 1;
}

for(new char = 0; char < strlen(string); char++)
{
format(output, 128, "%s%c", output, tolower(string[char]));
}
return output;
}
Maybe this?
Usage:
pawn Code:
xToLower(string[]);
Example:
pawn Code:
new String[12];
format(String, 12, "aCAUiFIUA");
printf("%s",xToLower(String));
Greetz,
LetsOWN
There are too many unnecessary checks and slow function usage in your code.
Shabi RoxX's direct replacement method should be the fastest and simplest I think. It has no limit on the input string size because it doesn't even need another string to store the output.
I also doubt "char" can be used as a variable/iterator as it's a reserved word. You can see the blue highlighting on it in your post.
Using strlen in the for loop check may also be slow for long strings (though the input string is short in this case). You should do something like
pawn Code:
for(new i = 0, len = strlen(string);i < len;i++)
Using format for simple string concatenation is also much slower than using strcat (I tested long time ago and found that it's about 4 to 5 times faster). I'll only use format when 3 to 4 strcats and strvals can't finish the job, or when I need special outputs (like hex). Using format on constant string is even slower than direct assignment. While you can simply do
pawn Code:
new String[12] = "aCAUiFIUA";
//or
new String[12];
String = "aCAUiFIUA";
, why do you need to use format?
Printing a single string can just use print(xToLower(String)).

Some may argue that we can't see the actual speed difference because the CPU is so fast, or they're just a little things that shouldn't be cared about too much, but at least it looks better and simpler, it's a good scripting practise.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)