lua初学笔记2之转义字符

这篇博客介绍了Lua中的转义字符,包括`a`(bell)、``(退格)、`f`(表格填充)、` `(换行)、` `(回车)、` `(水平制表符)、`v`(垂直制表符)、`\`(反斜杠)、`"`(双引号)、`'`(单引号)、`[`(左方括号)和`]`(右方括号)。同时,展示了如何进行多行字符串的输出以及如何使用`io.write()`忽略转义字符。此外,还讲解了Lua中字符串连接操作符`..`的用法和数字与字符串之间的转换规则。
print("\a");	--bell 硬件滴一声
print("a");
print("\b");	--back space	空格
print("b");
print("\f");	--from feed填充表格
print("\n");	--new line换行
print("\r");	--carriage reurn返回当前行第一列
print("\t");	--horizontal tab 水平换行
print("\v");	--填充表格
print("\\");	--backslach单斜杠
print("\"");	--double quote双引号
print("\'");	--single quote单引号
print("\[");	--left square bracket左中括号
print("\]");	--right square bracket


---------------------------------------------
print("one line\nnext line\n\"in quote\",\'in quotes\'");
print("''");	--可以
--print("" "");	--不可以
print("\"\"");	--必须转意字符


---------------照原样输出-----------------------------------
page = [[
\n\tttt\nn\yy
<.>
<>
<>
hh
]];
print(page);
io.write(page);	--用这种方法忽略转意字符按原样输出


--------------------lua的智能----------------------
print(10 .. 20); --..操作符必须加空格
print("10"+1);
print("10+1");


line = io.read();
n= tonumber(line);	--将读入的数据强制转换为number
if n == nil then 
	error(line .. " is vaild number");
else
	print(n*2);
end


print(tostring(10) == "10");
print(1 .. 0 == "10");
print(10 .. "" == "10");	--数字和字符串..为字符串"10"
print("10"+1 == 11);		--数字和字符串+ 为数字11
print(4 and 5);			--第一个为真第二个也为真 则输出第二个
a and b -->如果a为false 则返回a 否则返回b
a or b	-->如果a为true则返回a 否则返回b
and 优先级比 or高
 x = x or v;
==>
if not x then
	x=v;
end




                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值