|
| 02 Sep 2012 06:48 PM |
What does the 'i' mean in the wiki? It confuses me.. Like so: print(string.sub("Help..", 1, i)) -- What does 'i' mean? o.e Please help.. Thanks! -=Zack=- |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2012 06:49 PM |
Depends.... Where's the part it defines "i"?
(>•д•)> ¤¤ †KMXD† ¤¤ [SHG Tier~3] (^•д•^) [Freelancing Scripting Guru] <(•д•<) |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2012 06:50 PM |
Does this not confuse you? From the wiki: >Returns the substring of s that starts at i and continues until j; i and j may be >negative. If j is absent, then it is assumed to be equal to the length of s. In >particular, the call string.sub(s,1,j) returns s until as many characters as j, and >string.sub(s, -i) returns a suffix of s with length i.
O.E.. |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2012 06:51 PM |
Oops, I didn't mean for the arrows to be in the middle of that... -.o' Here:
Returns the substring of s that starts at i and continues until j; i and j may be negative. If j is absent, then it is assumed to be equal to the length of s. In particular, the call string.sub(s,1,j) returns s until as many characters as j, and string.sub(s, -i) returns a suffix of s with length i. |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2012 06:54 PM |
"s" would be the string, as you chose:
"Help"
It would start at i, and end at j. So if we did:
string.sub("Help", 1, 4)
> Help
But if I did:
string.sub("Help", 1, 3)
It would print:
> Hel
(>•д•)> ¤¤ †KMXD† ¤¤ [SHG Tier~3] (^•д•^) [Freelancing Scripting Guru] <(•д•<) |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2012 06:55 PM |
But what if I did string.sub("Hello", 1, i) ? |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2012 06:57 PM |
Nothing. But if you printed it, it would just return the whole string.
(>•д•)> ¤¤ †KMXD† ¤¤ [SHG Tier~3] (^•д•^) [Freelancing Scripting Guru] <(•д•<) |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2012 06:59 PM |
So what about:
print(string.sub("Hi!", 1, i - 2)) would print:
>H
Right? |
|
|
| Report Abuse |
|
|
TaslemGuy
|
  |
| Joined: 10 Jun 2009 |
| Total Posts: 12174 |
|
|
| 02 Sep 2012 06:59 PM |
string.sub( str, i, j)
returns the substring of str starting at i and ending at j.
string.sub( "12345" , 2, 4) --> "234" |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2012 07:01 PM |
@Taslem, I know that. -.e...
I just wanted to know what would happen if I used 'i' instead of a number. |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2012 07:01 PM |
print(string.sub("Hi!", 1, i - 2)) would print: > H
i would be a nil value.
(>•д•)> ¤¤ †KMXD† ¤¤ [SHG Tier~3] (^•д•^) [Freelancing Scripting Guru] <(•д•<) |
|
|
| Report Abuse |
|
|
TaslemGuy
|
  |
| Joined: 10 Jun 2009 |
| Total Posts: 12174 |
|
|
| 02 Sep 2012 07:02 PM |
@zack
Then i is a variable, and whatever its value would be used.
That's how variables work. |
|
|
| Report Abuse |
|
|
| |
|
TaslemGuy
|
  |
| Joined: 10 Jun 2009 |
| Total Posts: 12174 |
|
|
| 02 Sep 2012 07:04 PM |
Names are variables, regardless of their context.
Do you not know what a variable is? |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2012 07:11 PM |
Yes I do. -.-
local apple = "Hi"
print(apple)
|
|
|
| Report Abuse |
|
|
TaslemGuy
|
  |
| Joined: 10 Jun 2009 |
| Total Posts: 12174 |
|
| |
|
| |
|