Uppercase, Lowercase, Leading zeros, Reverse, Repeat, ASCII Keycode, etc.

HopscotchHopscotch Member, PRO Posts: 2,782
edited October 2015 in Working with GS (Mac)

Here are some useful LUA string and pattern matching hacks

that will make life easier:

Just add the function to the end of your attribute, joined by a ":"

.
Convert text to all uppercase:

self.Uppercase = self.Lowercase:upper()

.
Convert text to all lowercase:

self.Lowercase = self.Uppercase:lower()

.
Reverse a string of text:

self.Backwardtext = self.Forwardtext:reverse()

.
Repeat a string of text:

n is the number or repetitions of the whole text

self.Longwinded = self.Shortwinded:rep(n)

.
Get the ASCII Keycode of a character:

n is the character position in the string of text

self.AsciiNumber = self.Text:byte(n)

.
Get the character from its ASCII Keycode:

self.FormattingStyle = "%c"

self.TheCharacter = self.FormattingStyle:format(self.TheASCIIValue)

.
Leading and trailing zeros:

n = total number of characters
m = number of decimal places

for more formatting options search for printf and POSIX

self.FormattingStyle = "%0n.0mf"

self.FormattedNumber = self.FormattingStyle:format(self.NumberToBeFormatted)

Comments

Sign In or Register to comment.