Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

String.sub() is confusing me, explain ?

Asked by 3 years ago

Hi, I've already read the article about string.sub() but I find it a bit confusing. Can someone explain this to me more clearly than the article so that I can have a better understanding, many thanks ????

Article about strings --> https://developer.roblox.com/en-us/api-reference/lua-docs/string

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.
0
Would I be able to delete strings using string.sub() ? AK47GOLDgun 9 — 3y
0
By that I mean deleting certain characters AK47GOLDgun 9 — 3y
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. shadowstorm440 590 — 3y
0
I would like an example AK47GOLDgun 9 — 3y
View all comments (3 more)
0
Edited in, check. shadowstorm440 590 — 3y
0
Many thanks AK47GOLDgun 9 — 3y
0
Welcome, good luck scripting. shadowstorm440 590 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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

example.

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

Output

"Hel"

Answer this question