VBA中的Str函数用于Excel为字符串添加一个字符 [英] Str Function in VBA for Excel adds a character to the string
问题描述
我使用str()函数将整数转换为字符
但是,我注意到str()函数会返回一个额外的字符到字符串。
例如, MsgBox(Len(str(1)))
将返回2。 b
$ b
附加的额外字符是什么?
p>
当数字转换为字符串时,前缀空格总是为数字的符号保留,如果数字为正,则返回的字符串包含一个前导空格,加号隐含。
确保足够的语句在调试窗口中返回True:
? left(str(1),1)=
I am converting an integer to string using the str() function
However, I noticed that the str() function would return an extra character to the string.
For example, MsgBox(Len(str(1)))
would return 2.
What is the extra character being appended?
From Excel 2010 help:
"When numbers are converted to strings, a leading space is always reserved for the sign of number. If number is positive, the returned string contains a leading space and the plus sign is implied."
And sure enough this statement returns True in the debug window:
? left(str(1),1) = " "
这篇关于VBA中的Str函数用于Excel为字符串添加一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!