Results 1 to 3 of 3

Thread: [RESOLVED] Searching a Large String

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    UK
    Posts
    489

    Resolved [RESOLVED] Searching a Large String

    Hey

    Well I haven't programmed for some time, so I'm a little rusty .

    Basically I'm storing HTML within a variable, and I need to count the amount of times a specific element appears e.g. <h3 class=r> for now.

    I thought of using a for each loop, and passing the string above into the parentheses of the loop (using a variable ofc) however for many reason's, I don't think this has a chance of working (won't bother explaining why, as I assume you can guess). Then thought of using the .Contains method of the string class, but I simply can't think of how to use it with what I'm trying to do.

    Help appreciated.
    Learning C♯

    Data Binding & Bound Controls - Objects and wizards will never be as intelligent as you, do it yourself! (Unless your Pro)

  2. #2
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Searching a Large String

    I was able to create a procedure to do this in about 5 minutes using .IndexOf(WORD, Starting Index).

    Just declare an Index variable and have a While loop to keep going until .IndexOf(word, index) returns -1, while it loops, keep setting the index variable = to the next index of the word (+ the words length so you don't get stuck).
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Searching a Large String

    try this. its the quickest way:

    vb Code:
    1. Dim wc As New Net.WebClient
    2. Dim html As String = wc.DownloadString(url)
    3. Dim rx As New System.Text.RegularExpressions.Regex("<h3 class=r>")
    4. MsgBox(rx.Matches(html).Count)

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