Strmid - Incorrect Usage?
#1

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

https://sampwiki.blast.hk/wiki/Strmid
Reply
#3

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);
Reply
#4

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

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));
Reply
#6

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

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).
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)