Counting the number of occurrences of a character... 
Author Message
 Counting the number of occurrences of a character...

I am looking for a way to count the number of occurrences of a character in
my vb code.

Example:
exampleStr = "This is ; just a test; to show; an example"

I would like to be able to know how many times the character ";" occurs in
the variable exampleStr. I need a numeric number to be returned. Could

Thanks for the help!!



Sun, 09 Feb 2003 03:00:00 GMT  
 Counting the number of occurrences of a character...

There is no single function that does this for you.

You would have to do a do while loop using InStr
and just keep going until InStr() returns 0.

-Chad


Quote:
> I am looking for a way to count the number of occurrences of a character in
> my vb code.

> Example:
> exampleStr = "This is ; just a test; to show; an example"

> I would like to be able to know how many times the character ";" occurs in
> the variable exampleStr. I need a numeric number to be returned. Could

> Thanks for the help!!



Sun, 09 Feb 2003 03:00:00 GMT  
 Counting the number of occurrences of a character...

Function StringCount(TheString,StringToCount)
    StringCount = Ubound(Split(TheString,StringToCount,-1,1))
End Function

The above function is case-insensitive. To make it case-sensitive
change the last 1 to a 0. Note that you aren't limited to counting a
single character; you can count also count word occurrences or any
other string of characters.

As an example, Msgbox StringCount("This is ; just a test; to show; an
example",";") echoes 3.


: I am looking for a way to count the number of occurrences of a
character in
: my vb code.
:
: Example:
: exampleStr = "This is ; just a test; to show; an example"
:
: I would like to be able to know how many times the character ";"
occurs in
: the variable exampleStr. I need a numeric number to be returned.
Could

:
: Thanks for the help!!
:
:



Sun, 09 Feb 2003 03:00:00 GMT  
 Counting the number of occurrences of a character...
str = "This is ; just a test; to show; an example"
Dim arChars(255)
for n = 1 to len(str)
  i = asc(mid(str,n,1))
  arChars(i) = arChars(i) + 1
next

char = ";"
msgbox "The character --> " & char _
     & " <-- occurs " & arChars(asc(char)) _
     & " times"

PS - It's not considered polite to ask for an email reply to a newsgroup post...

--
Michael Harris
Microsoft.MVP.Scripting
--


I am looking for a way to count the number of occurrences of a character in
my vb code.

Example:
exampleStr = "This is ; just a test; to show; an example"

I would like to be able to know how many times the character ";" occurs in
the variable exampleStr. I need a numeric number to be returned. Could

Thanks for the help!!



Sun, 09 Feb 2003 03:00:00 GMT  
 Counting the number of occurrences of a character...
see at:

http://msdn.microsoft.com/voices/office08032000.asp
-----------------------


Quote:
> I am looking for a way to count the number of occurrences of a character
in
> my vb code.

> Example:
> exampleStr = "This is ; just a test; to show; an example"

> I would like to be able to know how many times the character ";" occurs in
> the variable exampleStr. I need a numeric number to be returned. Could

> Thanks for the help!!



Sun, 09 Feb 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. counting the number of occurrences of a characher in a string

2. count number of characters in a string

3. Counting number of characters in a text box

4. Count of occurrences (Word 2k)

5. Strange occurrence with non-printing characters.

6. running character count

7. Counting characters as they are typed

8. counting characters in a string

9. COUNT OF CHARACTERS IN A MAIL

10. How to count the Reference Characters ?

11. Count occurances of a character string?

12. Ignore strikethrough text in document character count

 

 
Powered by phpBB® Forum Software