Using string functions.

How to use the string functions.

by DEVLOgiC_1

Author Avatar

This tutorial is based on the string functions and will require some basic scripting knowledge.

An Introdution to: string.match()

string.match is a function to detect patterns in strings. For instance, let's say I have 2 variables that represent strings.

local StringToDetect = "Hello, world!"
local WhatToDetect = "ello, wo"

Now, let's say I wanted to print the matching patterns in our Strings, that's where string.match() comes in:

print(string.match(StringToDetect,WhatToDetect))

Output:

ello, wo

Explanation:

Now, the reason it does this is because some of the letters in our variable "StringToDetect" matches some of the characters in the variable "WhatToDetect". I'm pretty sure you will be able to get the hang of it.

An Introduction to: string.rep()

string.rep() is a function for repetition. If I wanted to print out "DEVLOgiC_1 IS THE BEST ROBLOXIAN" 5 times, which I'm sure you do too, most of you would write it like this:

print("DEVLOgiC_1 IS THE BEST ROBLOXIAN")
print("DEVLOgiC_1 IS THE BEST ROBLOXIAN")
print("DEVLOgiC_1 IS THE BEST ROBLOXIAN")
print("DEVLOgiC_1 IS THE BEST ROBLOXIAN")
print("DEVLOgiC_1 IS THE BEST ROBLOXIAN")

Or:

for i = 1,5 do
    print("DEVLOgiC_1 IS THE BEST ROBLOXIAN")
end

But, what If I told you there was a simpler way to do this?! This is where string.rep() comes in.

print(string.rep("DEVLOgiC_1 IS THE BEST ROBLOXIAN",5))

Explanation:

string.rep() prints the first argument as much as the second argument.

An Introduction to: string.reverse()

string.reverse() is a function to reverse a string you put in:

so, let's say I had a variable called "Example"

local Example = "DEVLOgiC_1 IS THE BEST ROBLOXIAN"

Now, I can reverse the string using: string.reverse()

print(string.reverse(Example))

Output:

NAIXOLBOR TSEB EHT SI 1_CigOLVED

An Introduction to: string.upper()

string.upper() is a function to capatalize every single letter of your string. Pretty simple.

I want to make a variable called "IAMCOOL"

local IAMCOOL = "i am cool"

Now, I want to make this variable all capitalized, I would use string.upper()

print(string.upper(IAMCOOL))

Output:

I AM COOL

OMG it's telling the truth for once O: ^

An Introduction to: string.lower()

string.lower() is like string.upper() except it makes the string all lower case.

print(string.lower(" I LIKE CHOCOLATE, DO YOU?? "))

Output

i like chocolate, do you??

I don't really think I need to explain this function anymore.

An Introduction to: string.len()

string.len() is a function to recieve the amount of characters that are in the string. (spaces are included)

Example:

print(string.len("DEVLOgiC_1 IS COOL"))

Output:

18

An Introduction to: string.format()

Think of string.format() as a way to edit strings on the go. To me, it's kind of confusing. I will try to explain it. I think of it as a way to leave blanks in the string and then edit them later. You can leave blanks by using "%q", but there are many ways to leave blanks. Here is an example:

Example:

print(string.format("I like to eat %q.", "Pizza"))

Output:

I like to eat "Pizza".

Wrapping It Up:

I hope you enjoyed my first tutorial, please thumbs up and give me your feedback on how to make this tutorial better. Thank you so much! I will be updating this tutorial more soon.

View in-game to comment, award, and more!