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
are converted to strings and concatenated together, and the resulting string is converted back to
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将变成一个字符串,它被转换成数字在执行加法运算前。如果数字
字符出现在字符串的合并中,它们将会被转成字符串。如下:
print (two three) + 4
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的值。
本文详细解释了在AWK程序中如何将字符串转换为数字,以及如何将数字转换为字符串的过程。通过具体例子,展示了在不同场景下进行转换的操作方式,包括在表达式中遇到字符串和数字时的处理逻辑。

被折叠的 条评论
为什么被折叠?



