CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2001
    Location
    Prague, Czech Republic
    Posts
    43

    Count character occurances

    Is there a function or something to count the number of occurances of a specific character in a string?

    I can implement it using a loop and InStr(), but a builtin would definitely be quicker.

    I'm using VB 6.0.

    Thanks, Jenda


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Count character occurances

    I'm affraid there's no such function available in VB... so you will have to do it using Instr.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Sep 2001
    Location
    Prague, Czech Republic
    Posts
    43

    Re: Count character occurances

    Well what could I expect.

    Thanks, Jenda


  4. #4
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: Count character occurances

    Try the Split function. Exrivate Sub Command1_Click()
    Dim sText as string
    sText = "abc3456copchj"
    MsgBox UBound(Split(sText, "c"))
    End Sub




  5. #5
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    Re: Count character occurances

    Funny there is a Replace function but not the function you need...

    Dim str as string
    Dim len1 as Integer
    str = "fds11fdgfdgd343111g"
    len1 = len(str)
    str = Replace$(str, "1", vbNullString)
    MsgBox len1 - len(str)




    ----------
    The @host is everywhere!
    ----------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured