By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

Parsing a string - please help

P: n/a
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

Jan 20 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
------------------
<al*****@altavista.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.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

Jan 20 '06 #2

P: n/a
Ken,

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

Merci,
Al.

Jan 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.