Two minor str questions.
#1

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

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

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

Oh thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)