A
almurph
Intern Strings - am I usingthem right.
I have heard a lot about intern string - so I wanted to use them to
increas e speed of processing.
I have a hastable that I am using to parse a string of the form:
wordA wordB wordC wordD etc etc
I want to de-duplicate the string - that is, remove any repeated words
so that only 1 occurance of the word exists.
Its working fine - takes about 25 mins to do all the strings that I
have for it so I intriduced the line:
String.Intern(s)
in an effort in incrase spped of processing. My question is though -
am I using intern string correctly? Am I msiing anything or using them
incorrectly? Any comments/suggestions/code-samples much appreciated.
Al.
******** CODE AS FOLLOWS ********
Public Function DeDuplicate(ByVal str As String) As String
Dim ht As New Hashtable
Dim s As String
For Each s In str.Split(" "c)
Try
String.Intern(s)
If Not ht.ContainsKey(s) Then
ht.Add(s, s)
End If
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
Next
'Convert hashtable -> string
Dim deDupStr As String
Dim Item As DictionaryEntry
For Each Item In ht
'String.Intern(deDupStr)
'Trace.WriteLine(Item.Value)
deDupStr += Item.Value.ToString + " "
Next
Return deDupStr.Trim()
End Function
I have heard a lot about intern string - so I wanted to use them to
increas e speed of processing.
I have a hastable that I am using to parse a string of the form:
wordA wordB wordC wordD etc etc
I want to de-duplicate the string - that is, remove any repeated words
so that only 1 occurance of the word exists.
Its working fine - takes about 25 mins to do all the strings that I
have for it so I intriduced the line:
String.Intern(s)
in an effort in incrase spped of processing. My question is though -
am I using intern string correctly? Am I msiing anything or using them
incorrectly? Any comments/suggestions/code-samples much appreciated.
Al.
******** CODE AS FOLLOWS ********
Public Function DeDuplicate(ByVal str As String) As String
Dim ht As New Hashtable
Dim s As String
For Each s In str.Split(" "c)
Try
String.Intern(s)
If Not ht.ContainsKey(s) Then
ht.Add(s, s)
End If
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
Next
'Convert hashtable -> string
Dim deDupStr As String
Dim Item As DictionaryEntry
For Each Item In ht
'String.Intern(deDupStr)
'Trace.WriteLine(Item.Value)
deDupStr += Item.Value.ToString + " "
Next
Return deDupStr.Trim()
End Function