Lua之轉義字符


  1. print("\a");    --bell 硬件滴一聲  
 
  1. print("a");  
  2. print("\b");    --back space    空格  
  3. print("b");  
  4. print("\f");    --from feed填充表格  
  5. print("\n");    --new line換行  
  6. print("\r");    --carriage reurn返回當前行第一列  
  7. print("\t");    --horizontal tab 水平換行  
  8. print("\v");    --填充表格  
  9. print("\\");    --backslach單斜杠  
  10. print("\"");    --double quote雙引號  
  11. print("\'");    --single quote單引號  
  12. print("\[");    --left square bracket左中括號  
  13. print("\]");    --right square bracket  
  14.   
  15.   
  16. ---------------------------------------------  
  17. print("one line\nnext line\n\"in quote\",\'in quotes\'");  
  18. print("''");    --可以  
  19. --print("" ""); --不可以  
  20. print("\"\"");  --必須轉意字符  
  21.   
  22.   
  23. ---------------照原樣輸出-----------------------------------  
  24. page = [[  
  25. \n\tttt\nn\yy  
  26. <.>  
  27. <>  
  28. <>  
  29. hh  
  30. ]];  
  31. print(page);  
  32. io.write(page); --用這種方法忽略轉意字符按原樣輸出  
  33.   
  34.   
  35. --------------------lua的智能----------------------  
  36. print(10 .. 20); --..操作符必須加空格  
  37. print("10"+1);  
  38. print("10+1");  
  39.   
  40.   
  41. line = io.read();  
  42. n= tonumber(line);  --將讀入的數據強制轉換為number  
  43. if n == nil then   
  44.     error(line .. " is vaild number");  
  45. else  
  46.     print(n*2);  
  47. end  
  48.   
  49.   
  50. print(tostring(10) == "10");  
  51. print(1 .. 0 == "10");  
  52. print(10 .. "" == "10");    --數字和字符串..為字符串"10"  
  53. print("10"+1 == 11);        --數字和字符串+ 為數字11  
  54. print(4 and 5);         --第一個為真第二個也為真 則輸出第二個<pre name="code" class="html">a and b -->如果a為false 則返回a 否則返回b  
  55. a or b  -->如果a為true則返回a 否則返回b  
  56. and 優先級比 or高  
  57.  x = x or v;  
  58. ==>  
  59. if not x then  
  60.     x=v;  
  61. end</pre><br>  
  62. <pre></pre>  
  63. <pre name="code" class="plain"><pre></pre>  
  64. <pre></pre>  
  65.      
  66. </pre>  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM