Which way to measure a chain is better?

Recently I ran into a question about the continuous use of strings: What is better to use to measure a string?

local Text= "Hello"

print(Text:len())
print(string.len(Text))
print(#Text)

This is the preferred method, using this is better than using the # version (not exactly sure why, part of it might be like what @SkiuulLPcz said and it might make it confusing). This method is also better than

This because it is up to 30% more efficient.

1 Like

Text:len() is the most unoptimized way to work with strings period.

Always use for example in this case string.len()

It may be possible that #Text is faster, but you should still stick with using string.len
for bigger projects(It might be confusing using next to tables)

Example:

local tbl = {"Hallo there","abc","etc"}

local str = "Hello there"

for i=1,#tbl do

    if #tbl[i] == #str then end

end

for i=1,#tbl do

    if string.len(tbl[i]) == string.len(str) then end

end
1 Like