generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: String.sub?

Previous Thread :: Next Thread 
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
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
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
02 Sep 2012 06:49 PM
Depends.... Where's the part it defines "i"?

(>•д•)> ¤¤ †KMXD† ¤¤ [SHG Tier~3] (^•д•^) [Freelancing Scripting Guru] <(•д•<)
Report Abuse
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
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
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
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
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
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
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
02 Sep 2012 06:55 PM
But what if I did
string.sub("Hello", 1, i) ?
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
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
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
02 Sep 2012 06:59 PM
So what about:

print(string.sub("Hi!", 1, i - 2)) would print:

>H

Right?
Report Abuse
TaslemGuy is not online. 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
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
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
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
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 is not online. 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
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
02 Sep 2012 07:02 PM
I'm confused..

D:
Report Abuse
TaslemGuy is not online. 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
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
02 Sep 2012 07:11 PM
Yes I do.
-.-

local apple = "Hi"

print(apple)
Report Abuse
TaslemGuy is not online. TaslemGuy
Joined: 10 Jun 2009
Total Posts: 12174
02 Sep 2012 07:12 PM
Then what's not to get?
Report Abuse
zackeryjerrypowers is not online. zackeryjerrypowers
Joined: 01 Aug 2008
Total Posts: 1515
02 Sep 2012 07:12 PM
Nevermind. e.e'
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image