Created
November 29, 2014 16:12
-
-
Save srdjan-m/daa4aaf87da0fe068818 to your computer and use it in GitHub Desktop.
lua: string splitting by character position
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(string.sub("123456789", 1)) --should print original string | |
print(string.sub("123456789", 1, -1)) --should print original string | |
print(string.sub("123456789", 4, 7)) --should print 4567 | |
print(string.sub("123456789", 1, 4)) --should print the 1st 4 chars | |
print(string.sub("123456789", -4, -1)) --should print the last 4 chars | |
print(string.sub("123456789", 2, -2)) --should remove the first and last char | |
print(string.sub("123456789", 2)) --should remove the first char | |
print(string.sub("123456789", 1, -2)) --should remove the last char | |
print(string.sub("123456789", -2)) --should print only the last 2 chars | |
print(string.sub("123456789", 1, 2)) --should print only the first 2 chars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment