Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

String.sub() is confusing me, explain ?

2 answers

✓ Accepted answer

The first argument of string.sub() is usually referred to as the String obviously, this is the string you will be using in string.sub().

The second argument of string.sub() is referred to as i and is the starting point for the string, this will then go to the third argument referred to as j which will return a string counting the character arguments i and j

-- > all vanilla string libaries.

-- > example usage:

local String = "WOW! YOU CAN DO THIS?"
local i = 5

string.sub(String, i) -- no j argument, goes to end.

-- > output: YOU CAN DO THIS?

-- > example of string.gsub() as asked in comments:

local String = "Hello, i don't like you!"
local GSUB = string.gsub(String, "i don't like you!", "i like you!")

print(GSUB)

-- > output: Hello, i like you!
-- > explain:
-- > the first argument of string.gsub() is the string, the second is what you want to replace and the third is what you want to replace it with.

7 comments

0

Would I be able to delete strings using string.sub() ?

0

By that I mean deleting certain characters

0

not really, you would need to use string.gsub() to replace the certain characters you want i can edit an example in if you want.

0

I would like an example

0

Edited in, check.

0

Many thanks

0

Welcome, good luck scripting.

string.sub("String",Beginning number, End number)

example.

print (string.sub("Hello", 1, 3))

Output

"Hel"

This discussion is preserved as it was. New answers, comments, and votes are closed.