Conversion of Strings and Numbers-AWK零碎2--【每日一译】--20130202

本文详细解释了在AWK程序中如何将字符串转换为数字,以及如何将数字转换为字符串的过程。通过具体例子,展示了在不同场景下进行转换的操作方式,包括在表达式中遇到字符串和数字时的处理逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Strings are converted to numbers, and numbers to strings, if the context of the awk program
demands it. For example, if the value of either foo or bar in the expression foo + bar happens to
be a string, it is converted to a number before the addition is performed. If numeric values appear

in string concatenation, they are converted to strings. Consider this:

译:字符串转换成数字,和数字转换成字符串,当AWK程序的上下文环境需要它时。比如值是

“foo"或"bar"在表达式中foo+bar将变成一个字符串,它被转换成数字在执行加法运算前。如果数字

字符出现在字符串的合并中,它们将会被转成字符串。如下:


two = 2; three = 3

print (two three) + 4



This eventually prints the (numeric) value 27. The numeric values of the variables two and three
are converted to strings and concatenated together, and the resulting string is converted back to

the number 23, to which 4 is then added.

这个最终的打印数字的结果值为27.这些变量的数字值2和3被转换成字符和合并在一起,并且结果字符串

被转换回成23,加上4的值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值