Wednesday, May 16, 2012

String 예제

 y = 2012; m = 3; d = 1  
 s = string.format("%04d-%02d-%02d", y, m, d)  
 print(s)  
   
 s = string.format("%.4f", math.pi)  
 print(s)  
   
 s = "This is for you. I love you."  
 i = string.find(s, "you")  
 print(i)  
 i = string.find(s, "you", i+1)  
 print(i)  
   
 s = string.gsub(s, "you", "Jenny")  
 print(s)  
   
 s = "My girlfriend(Jenny) is lovely(cute(pretty))"  
 s = string.gsub(s, "%b()", "(---)")  
 print(s)  
레퍼런스 : Programming in Lua / Chapter 20. The String Library

No comments:

Post a Comment