VBA中哪个命令可以计算字符串变量中的字符数?

发布于 2024-08-10 14:03:00 字数 136 浏览 3 评论 0原文

假设我有这个变量:

word =“habit”,

VBA 中的哪个命令将允许我计算这个变量中有多少个字符(在我的例子中是 5)。

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

Let's say I have this variable:

word = "habit"

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

岁月无声 2024-08-17 14:03:01

你的意思是计算字符串中的字符数吗?这很简单

Dim strWord As String
Dim lngNumberOfCharacters as Long

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

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
荆棘i 2024-08-17 14:03:01
Len(word)

虽然这不是你的问题标题所问的=)

Len(word)

Although that's not what your question title asks =)

野鹿林 2024-08-17 14:03:01

试试这个:

word = "habit"
findchar = 'b"
replacechar = ""
charactercount = len(word) - len(replace(word,findchar,replacechar))

Try this:

word = "habit"
findchar = 'b"
replacechar = ""
charactercount = len(word) - len(replace(word,findchar,replacechar))
独自唱情﹋歌 2024-08-17 14:03:01

莱恩就是你想要的。

word = "habit"  
length = Len(word)

Len is what you want.

word = "habit"  
length = Len(word)
扭转时空 2024-08-17 14:03:01

使用 Len 函数

length = Len(myString)

Use the Len function

length = Len(myString)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文