VBA中的Str函数用于Excel为字符串添加一个字符 [英] Str Function in VBA for Excel adds a character to the string

查看:2284
本文介绍了VBA中的Str函数用于Excel为字符串添加一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆