lua-users home
lua-l archive

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

On Sat, Oct 16, 2010 at 7:43 PM, Maxime Chupin <> wrote:

I don't really inderstand how work %s. For example, I wrote this code (probabely, it is not a a beautiful code :-)) :


t="cou   cou2 co\nu3   cou4    ";
print("1 : "..a[1]);
print("2 : "..a[2]);
print("3 : "..a[3]);
print("4 : "..a[4]);
print("5 : "..a[5]);

Why does not it  work as I want ? %s is not only for the space ?

Based on the result, I'd say that it includes newline and carriage return characters.  I'd suggest you just use the plain space character (there doesn't seem to be any escaping of the space character necessary as it's not a regular _expression_) to match whitespace.  For example:

a=split(t,"([ <TAB>]+)");

Where you would replace <TAB> with an actual tab character.

Regards, James.