CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    68

    Get char occurance count

    Hello-

    What is the fastest way to determine if there are more than 1 "*" characters in a string?

    Thanks - Pipe


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Get char occurance count

    If you are using VB 6.0, the quickest way is to use the Split command with the "*" as the delimiter like so

    private Sub Command1_Click()
    Dim strString
    Dim strArray
    strString = "**********"
    strArray = Split(strString, "*")
    MsgBox UBound(strArray) + 1
    End Sub




    John G

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Get char occurance count

    split function with "*" as delimiter should be quite fast (I think more than instr function in a loop for the len of the string exiting when not found anymore).
    You will receive an array with ubound = number of "*" char -1.

    Maybe you could do some fancy tricks with binary data and Copymemory Api, but these are not my best way of working...


    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: whooops!

    Beated in speed by you.
    Sorry for my redundance, King.
    ;-)
    Have a nice day, J.G.D.

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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