Strmid - Incorrect Usage? -
DrakeX - 01.07.2014
I changed:
pawn Код:
format(PlayerInformation[playerid][String], 64, "N/A");
to:
pawn Код:
strmid(PlayerInformation[playerid][String], "N/A", 0, 64);
And it doesn't seem to have an effect -- does strmid only work when copying strings?
Re: Strmid - Incorrect Usage? -
Threshold - 01.07.2014
https://sampwiki.blast.hk/wiki/Strmid
Re: Strmid - Incorrect Usage? -
DrakeX - 01.07.2014
Real helpful...
Anyways, for anyone wondering how I managed to fix this, I changed:
pawn Код:
strmid(PlayerInformation[playerid][String], "N/A", 0, 64);
to:
pawn Код:
strmid(PlayerInformation[playerid][String], "N/A", 0, strlen("N/A"), 64);
Re: Strmid - Incorrect Usage? -
sammp - 01.07.2014
That method is very inefficient if I'm writing a long message, as the line is going to be huge.
An easier method can be this:
pawn Код:
new string[128];
strmid(string, "N/A", 0, sizeof(string), 128);
Correct me if im wrong.
Re: Strmid - Incorrect Usage? -
Jack_Leslie - 01.07.2014
Why would you want to use strmid anyway?
pawn Код:
format(PlayerInformation[playerid][String], 64, "N/A");
Is a lot easier in your case.
If you wanted to use strmid, it would need to be this:
pawn Код:
new string[126];
format(string, 126, "N/A");
strmid(PlayerInformation[playerid][String], string, 0, strlen(string), 126);
I'm sure you can tell the difference between the two - using strmid brings in unneeded lines and usage. Normally you would use strmid for something like this:
pawn Код:
new string[126];
format(string, 126, "%s", GetPlayersName(playerid));
strmid(PlayerInformation[playerid][Name], string, 0, strlen(string), 126);
Even then, you can use format, which in my opinion is a lot easier, because it would turn into:
pawn Код:
format(PlayerInformation[playerid][Name], 126, "%s", GetPlayersName(playerid));
Re: Strmid - Incorrect Usage? -
Threshold - 01.07.2014
Quote:
Originally Posted by DrakeX
Real helpful...
|
You asked:
"does strmid only work when copying strings?"
I gave you a page that explains EXACTLY what strmid is used for, and why you SHOULDN'T be using it for this situation.
Re: Strmid - Incorrect Usage? -
Konstantinos - 01.07.2014
Quote:
Originally Posted by Jack_Leslie
Why would you want to use strmid anyway?
pawn Код:
format(PlayerInformation[playerid][String], 64, "N/A");
Is a lot easier in your case.
If you wanted to use strmid, it would need to be this:
pawn Код:
new string[126]; format(string, 126, "N/A"); strmid(PlayerInformation[playerid][String], string, 0, strlen(string), 126);
I'm sure you can tell the difference between the two - using strmid brings in unneeded lines and usage. Normally you would use strmid for something like this:
pawn Код:
new string[126]; format(string, 126, "%s", GetPlayersName(playerid)); strmid(PlayerInformation[playerid][Name], string, 0, strlen(string), 126);
Even then, you can use format, which in my opinion is a lot easier, because it would turn into:
pawn Код:
format(PlayerInformation[playerid][Name], 126, "%s", GetPlayersName(playerid));
|
Don't! Format is slower - in fact, the best way to copy a string to another is memcpy or strcat (
https://sampforum.blast.hk/showthread.php?tid=309130).