You could probably use string.split()
for this.
local myString = "Hello, World!"
local substrings = myString:split(",") --//Table with 2 indices, one "Hello" and the other "World!"
No, that’s not what I mean, what I mean is
Let’s say I have string
local words = “Hello, World Nice job guys!”
It will only print “Hello, World!” Which is the world that is between and
Ahhh my question is error, wait.
I use picture to change the question, because if i write it gives error
You could solve this by using regular expression, or to be exact Patterns.
This link or this link could help you understand how patterns in lua work. It’s very powerful tool for string manipulation. Your case should be easily solved by this. I recommend learning this so you could use it in the future.
Yes but how to make so the html word doesn’t get printed too.
Take the string, find part <html>Hello, World</html>
then search for first occurrence of >
and last occurrence of <
and then substring the part between these characters which will finally result in Hello, World
.
This is pretty easy to do once you read over the documentation on the DevHub.
So here’s what I have (I did this online and not on roblox so it should work):
Too lazy to paste in the code so write it out >:D
Yes but how to make every time they found because I want it from user input.
Just make it a function that takes in the msg and returns the local variable two:
This way is to save data from storing unnecessary local variables:
local Msg = "<html>I hate when people ask me to make them code for free!<html>"
local function Example(msg)
-- to save data from being saved as "one" or "two"
return string.sub(string.sub(msg, 7, 99), 1, string.find(msg:sub(7,99), "<html>") -1)
end
print(Example(Msg))
Ive created a fairly simple script that detects when a < is passed (or you can change it) and removes the words until it finds a > (or you can change it again). But anyways heres the script:
local Words = '<html>Hello, World! </html>Hi, Guys!'
local Indicator = '<'
local Stopper = '>'
function RemoveIndicators()
local CrossedIndicator = false
local Result = ''
for First,Last in utf8.graphemes(Words) do
local Sub = string.sub(Words,Last,First)
if rawequal(Sub,Indicator) then
CrossedIndicator = true
end
if not CrossedIndicator then
Result = Result..Sub
end
if rawequal(Sub,Stopper) then
CrossedIndicator = false
end
end
return Result
end
Its as easy as this:
local yourString = "<html>Hello, world</html> <html>Hi, mom</html>"
yourString = string.gsub(yourString, "%b<>", "")
print(yourString) -- Hello, world Hi, mom
The %bxy
pattern matches everything between x
and y
including x
and y
.
I didnt even know you could do that! I definetly went over with this.
Why don’t you use a search engine and find an HTML parser? You do not RegEx html…
An example: https://github.com/msva/lua-htmlparser