Why does Lua’s "print" print print extra spaces in the arguments?

Asked

Viewed 76 times

4

I used the command print() concatenating a variable, but the output prints extra spaces. If I use the io.write(), this problem does not occur. Why this problem happens to the print()?

Example:

name = "Peter"

print("The length of the name is: ", #name)

Expected result: The length of the name is: 5

Result obtained: The length of the name is: 5

2 answers

5


  • 1

    Thanks a lot, I could understand. From what I understood print() is to use to print without formatting, if you have these cases is to use io.write()

3

Checking the documentation of the function print():

Takes any number of arguments and prints their values in stdout, using the function tostring() to convert each argument passed in a string. print() is not intended for exit formatted but only as a quick way to show a value, by example for debugging. For full control over the output, use string.format() and io.write().

Example using io.write():

nome = "Augusto Vasques"      
io.write("O comprimento da string é: ",#nome)    --O comprimento da string é: 15

Browser other questions tagged

You are not signed in. Login or sign up in order to post.