Jump to content




Help with strings.


  • You cannot reply to this topic
2 replies to this topic

#1 ebernerd

  • Members
  • 262 posts
  • LocationBoston, MA

Posted 01 February 2015 - 03:09 AM

I'm stuck with something
So, I am writing something that requires a certain character of a string. So, like, is there a way to return... say, the third letter of the string "love"? And it would return "v"?

Any idea?

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 01 February 2015 - 03:09 AM

print( string.sub( "love", 3, 3 ) )


#3 Quintuple Agent

  • Members
  • 107 posts
  • LocationThis page

Posted 01 February 2015 - 03:33 AM

Just to elaborate further, string.sub() takes (string,starting point,[ending point]), if no ending point is given it will just go to the end of the string.
You can also use negatives to work at the end of the string, such as
string.sub("love",-2)
would return "ve"
http://lua-users.org...LibraryTutorial

Edited by Quintuple Agent, 01 February 2015 - 03:34 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users