Skip to content

Instantly share code, notes, and snippets.

@srdjan-m
Created November 29, 2014 16:12
Show Gist options
  • Save srdjan-m/daa4aaf87da0fe068818 to your computer and use it in GitHub Desktop.
Save srdjan-m/daa4aaf87da0fe068818 to your computer and use it in GitHub Desktop.
lua: string splitting by character position
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