SA-MP Forums Archive
Two minor str questions. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Two minor str questions. (/showthread.php?tid=269881)



Two minor str questions. - ||123|| - 18.07.2011

1st question: Why do people use -1 in the pos offset of strfind? shouldn't it be 0? to start searching for the word from the first letter of the string? Please explain.

2nd question: I saw this code example of strval in Wiki:
pawn Код:
new string[4] = "250";
new iValue = strval(string); // iValue is now '250'
I don't understand whats the use of it when you can just do:
pawn Код:
iValue = string;
Please explain.

-Thankyou.


Re: Two minor str questions. - Mauzen - 18.07.2011

To the first question: dont know why people do this, or do you mean that -1:
pawn Код:
if(strfind("Are you in here?", "you", true) != -1)
In this case strfind returns -1 when the string wasnt found at all, so the != -1 means "is that substring somewhere in the string?"

To question 2:
iValue = string;
wont work, this either wont compile, or will put the byte-value of the first letter of the string into iValue, and not the 250.


Re: Two minor str questions. - [HiC]TheKiller - 18.07.2011

Quote:
Returns The number of characters before the sub string (the sub string's start position) or -1 if it's not found.
Pretty much strfind returns -1 if the string isn't found. For the second question, you cannot do that because the size of ivalue is different to the string. With string, it would return this:

pawn Код:
string[0] = "2";
string[1] = "5"
string[2] = "0"
wheras iValue would return

pawn Код:
iValue = 250;
One is a integer, one is a string, they cannot be set like that.


Re: Two minor str questions. - ||123|| - 18.07.2011

Oh thanks.