您的位置:首页 > 其它

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

2013-08-01 17:00 393 查看
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的值。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: