How Can I Know How Much Letters Are In A String?

Just a random question, no specific use, the title says it all

1 Like

Use string.len()

print(string.len("Hello World!")) --> 12 Characters

There are multiple solutions to this:

local str = "Hello!"

local sol_1 = string.len(str)

local sol_2 = utf8.len(str)
-- shouldn't be used for this purpose but it works

local sol_3 = str:len()

local sol_4 = #str

I would overall recommend the usage of the #, @desinied 's Solution isnt recommended as usage of the # operator is faster than string.len()

(accidental reply)

1 Like

Okay, thanks to both of you!
@DasKairo @desinied

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.