Home All Groups Group Topic Archive Search About

Parsing a string - please help

Author
20 Jan 2006 11:45 AM
almurph
Hi everyone,


    Hope that you can help me please? I have a string of the form:

wordA wordB wordC wordD etc etc


    I want to de-duplicate it- that is, I want to remeove any repeated
term (leaving only 1 occurance of all terms).

    What is the fastest way? I have lots of strings of this nature to
parse! Should I use a arraylist perhaps? Does VB.NET have a dedicated
method for doing this?

    Any comments/suggestions/code-samples much,. much appreciated.

Thank you,
Al

Author
20 Jan 2006 12:23 PM
Ken Tucker [MVP]
Hi,

        Maybe this will help.  The hash table has a key for each item.  When
I add an item to the hash table I use the word as a key and value.  I use
the hash tables containskey method to see if the word is new.

        Dim strTest As String = "one two three four five one two three six
five"
        Dim ht As New Hashtable

        For Each strWord As String In strTest.Split(" "c)
            Try
                If Not ht.ContainsKey(strWord) Then
                    ht.Add(strWord, strWord)
                End If
            Catch ex As Exception
                Trace.WriteLine(ex.ToString)
            End Try
        Next

        Dim de As DictionaryEntry
        For Each de In ht
            Trace.WriteLine(de.Value)
        Next


Ken
------------------
<almu***@altavista.com> wrote in message
Show quoteHide quote
news:1137757501.817537.91750@g43g2000cwa.googlegroups.com...
> Hi everyone,
>
>
> Hope that you can help me please? I have a string of the form:
>
> wordA wordB wordC wordD etc etc
>
>
> I want to de-duplicate it- that is, I want to remeove any repeated
> term (leaving only 1 occurance of all terms).
>
> What is the fastest way? I have lots of strings of this nature to
> parse! Should I use a arraylist perhaps? Does VB.NET have a dedicated
> method for doing this?
>
> Any comments/suggestions/code-samples much,. much appreciated.
>
> Thank you,
> Al
>
Author
20 Jan 2006 4:08 PM
almurph
Ken,

  Thanks a million - this is super fast man. Hash tables rock!

Merci,
Al.