Count number of tab characters in a string
RG III wrote:
On Wednesday, October 9, 2019 at 4:22:33 AM UTC-7, Claus Busch wrote:
i = Len(myStr) - Len(Replace(myStr, vbTab, ""))
It does not work with the following code:
str1 = "Apples oranges cakes"
i = Len(str1) - Len(Replace(str1, vbTab, ""))
MsgBox "Number of tabs: " & i
There are 4 tabs in str1, but it returns 0. It appears that tab
characters are converted to space characters in the VBA editor.
Might that be the problem?
Yes. Try this:
str1 = "Apples" & vbTab & vbTab & "oranges" & vbTab & vbTab & "cakes"
i = Len(str1) - Len(Replace(str1, vbTab, ""))
MsgBox "Number of tabs: " & i
--
If you have an apple and I have an apple and we exchange apples then you and
I will still each have one apple. But if you have an idea and I have an idea
and we exchange these ideas, then each of us will have two ideas.
-- George Bernard Shaw
|