[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: %s caracter class
- From: Maxime Chupin <mc@...>
- Date: Sat, 16 Oct 2010 09:43:22 +0100
Hi,
I don't really inderstand how work %s. For example, I wrote this code (probabely, it is not a a beautiful code :-)) :
--------------------------------------------------------
function split(chaine,motif)
local tableau={};
local num1,num2;
local chaineloc=chaine;
num1,num2=string.find(chaineloc,motif);
if num1==nil and num2==nil then
tableau=chaineloc;
else
local i=1;
while num1~=nil and num2~=nil do
tableau[i]=string.sub(chaineloc,1, num1);
chaineloc=string.sub(chaineloc,num2+1);
num1,num2=string.find(chaineloc,motif);
i=i+1;
end
if chaineloc~="" then
tableau[i]=chaineloc;
end
end
return tableau;
end
t="cou cou2 co\nu3 cou4 ";
a={};
a=split(t,"(%s+)");
print("1 : "..a[1]);
print("2 : "..a[2]);
print("3 : "..a[3]);
print("4 : "..a[4]);
print("5 : "..a[5]);
-------------------------------------------------------------
And this produce :
1 : cou
2 : cou2
3 : co
4 : u3
5 : cou4
I wanted:
1 : cou
2 : cou2
3 : co
u3
4 : cou4
Why does not it work as I want ? %s is not only for the space ?
Thanks.
Best regards,
--
Maxime Chupin
http://mc.notezik.com