Skip to content

New String Functions

Irtsa edited this page Feb 8, 2025 · 3 revisions

String Functions

These functions extend from the current String object/class from greyscript.

The following are a list of new functions that can be utilized.





capitalize

Will capitalize the first letter of said string.

print("hello!".capitalize)
-- "Hello!"


lfill (amount, filler)

Will fill space on the left side of the said string using filler until the length of the string is equal to amount.

print("hello".lfill(20))
-- "000000000000000hello"


print("hello".lfill(10, " "))
-- "               hello"


rfill (amount, filler)

Will fill space on the right side of the said string using filler until the length of the string is equal to amount.

print("hello".rfill(20))
-- "hello000000000000000"


print("hello".rfill(10, " "))
-- "hello               "


format (Variables)

Will replace instances of "{}" in said string with items given in Variables in the order of the given Variables.

print("Hello {}! Today is {}.".format(["User","Friday"]))
-- "Hello User! Today is Friday."


group (groupsize)

Will split the string into a list comprising of substrings of sizes equal to groupsize.

print("Hello! How are you?".group(3))
-- ["Hel", "lo!", " Ho", "w a", "re ", "you", "?"]


list

Will return the string as a list.

print("hello!".list)
-- ["h", "e", "l", "l", "o", "!"]

Clone this wiki locally