VBA中的哪个命令可以计算字符串变量中的字符数? [英] Which command in VBA can count the number of characters in a string variable?

查看:153
本文介绍了VBA中的哪个命令可以计算字符串变量中的字符数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说我有这个变量:

word = habit

word = "habit"

VBA中的哪个命令请允许我计算该变量中有多少个字符(在我的情况下为5)。

which command in VBA will allow me to count how many characters are there in this variable (in my case it's 5).

重要提示:变量 word仅包含一个单词,不包含空格,但可能包含数字和连字符。

Important: the variable "word" contains only one word, no spaces, but may have contain numbers and hyphens.

推荐答案

您的意思是计算字符串中的字符数吗?

Do you mean counting the number of characters in a string? That's very simple

Dim strWord As String
Dim lngNumberOfCharacters as Long

strWord = "habit"
lngNumberOfCharacters = Len(strWord)
Debug.Print lngNumberOfCharacters

这篇关于VBA中的哪个命令可以计算字符串变量中的字符数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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