tolower output -
Dotayuri - 13.02.2013
Ok so i have
PHP Code:
new
username[MAX_PLAYER_NAME]
;
GetPlayerName(playerid, username, sizeof(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 ?
Re: tolower output -
Shabi RoxX - 13.02.2013
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
Re: tolower output -
Dotayuri - 13.02.2013
Is that really the only way ?
in PHP i wouldnt think of doing that
Re: tolower output -
Dotayuri - 13.02.2013
Quote:
Originally Posted by Shabi RoxX
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
Re: tolower output -
Shabi RoxX - 13.02.2013
Quote:
Originally Posted by Dotayuri
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
Re: tolower output -
Mmartin - 13.02.2013
Quote:
Originally Posted by Dotayuri
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])
Re: tolower output -
S0n1COwnsYou - 13.02.2013
try this,
PHP Code:
new username[MAX_PLAYER_NAME];
GetPlayerName(playerid, username, sizeof(username));
for(new i = 0; i <= 24; i++)
{
username[i] = tolower(username[i]);
}
Re: tolower output -
LetsOWN[PL] - 13.02.2013
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:
Example:
pawn Code:
new String[12];
format(String, 12, "aCAUiFIUA");
printf("%s",xToLower(String));
Greetz,
LetsOWN
Re: tolower output -
Dotayuri - 13.02.2013
Quote:
Originally Posted by LetsOWN[PL]
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:
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(String, 12, "aCAUiFIUA");
printf("%s",xToLower(String));
And i could just do that for any functions i need ?
Re: tolower output -
Jefff - 13.02.2013
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);
Re: tolower output -
leong124 - 14.02.2013
Quote:
Originally Posted by LetsOWN[PL]
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:
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.