lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Thanks Sam, it's a nice lua example.

Thanks Mike and Lorenzo, but actualy I don't really care about how a string with <newline> is being translated to form the string between quotes.

I'm very sorry, and I apologize for my awkward expression.

I mean, you're just want a result with quotes, some <backslash>s between them explaining some special char, that's it.

I mean, why not to let the string readable and printable? It's just a piece of string, readable strings are easy to debug, easy to process manually, and easy to talk about it for sure.

In other word, if there's a way to form them readable in one line, and could be used as source string as well, for purpose of ease, why not to do it?

I think this is the easiest way to fill this requirement:
if (*s == '"' || *s == '\\' /*|| *s == '\n'*/) { // I just comment this...


by the way, I found a bug (or not?):
s = [[

two new lines before me]]
print (string.format('%q', s))

OUTPUT:
"\
two new lines before me"