Parsing a string - please help

A

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
 
K

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top