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

Help with locating which letter or number in text is ordered 1 to last?

Asked by 3 years ago

Example : Photo I just want help with finding out how to make stuff happen to specific numbers or letters in text. Like if i want letter 1 to be bolded and letter 2 to be underlined or whatever. Please help :D

1 answer

Log in to vote
0
Answered by 3 years ago

There is a list of methods under the Lua name string. Which you can use to manipulate strings in a lot of ways.

If you think of a string as a table it makes more sense. Look at the following example:

local text = "Dulce et decorum est, pro patria mori."

for i = 1, string.len(text) do
    print(string.sub(text, i, i)
end

-- prints D, u, l, c, e, [SPACE]... and so on

You could then replace all instances of the letter E with V.

local text = "Dulce et decorum est, pro patria mori."
local processedString = ""

for i = 1, string.len(text) do
    if string.sub(text, i, i) == ("e" or "E") then
        processedString ..= "v"
    else
        processedString ..= string.sub(text, i, i)
    end
end

print(processedString) -- prints "Dulcv vt dvcorum..."

Read more about strings here.

Ad

Answer this question