Shamzki
Shamzki

Reputation: 3

Lua string append function size versus hard-coded string

I call string.len on "\005\033\011\045" it returns 4

whereas if I create a string like,

str = "\005" .. "\033" .. "\011" .. "\045"

and do string.len(str) it returns 16

forgive me if my code is not complete

Upvotes: 0

Views: 124

Answers (1)

Nifim
Nifim

Reputation: 5031

Both strings have a length of 4:

str = "\005\033\011\045"

str_concat = "\005" .. "\033" .. "\011" .. "\045"

print(string.len(str), string.len(str_concat))

If you are try to dynamically create a char, as would be indicated by some information you provided in the comments you need to do it like this:

str_concat = "\005" .. "\033" .. "\011" .. string.char(45) -- note string.char excepts a number value.    

Upvotes: 2

Related Questions