Connecting Tech Pros Worldwide Forums | Help | Site Map

Intern Strings - am I using them right? Please help!

almurph@altavista.com
Guest
 
Posts: n/a
#1: Jan 23 '06
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


Mattias Sjögren
Guest
 
Posts: n/a
#2: Jan 23 '06

re: Intern Strings - am I using them right? Please help!


> I have heard a lot about intern string - so I wanted to use them to[color=blue]
>increas e speed of processing.[/color]

I think you could gain more by using a StringBuilder when recreating
the stirng instead of the += operator.

[color=blue]
>String.Intern(s)
>
> in an effort in incrase spped of processing. My question is though -
>am I using intern string correctly?[/color]

Why do you think interning ths string would make your processing
faster? Did you see any performance increase?


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
almurph@altavista.com
Guest
 
Posts: n/a
#3: Jan 24 '06

re: Intern Strings - am I using them right? Please help!



Mattias Sjögren wrote:[color=blue][color=green]
> > I have heard a lot about intern string - so I wanted to use them to
> >increas e speed of processing.[/color]
>
> I think you could gain more by using a StringBuilder when recreating
> the stirng instead of the += operator.[/color]

Thanks. I'll try this and see does it imporve speed of processing.
[color=blue][color=green]
> >String.Intern(s)
> >
> > in an effort in incrase spped of processing. My question is though -
> >am I using intern string correctly?[/color]
>
> Why do you think interning ths string would make your processing
> faster? Did you see any performance increase?[/color]

No - afraid not. Nothing amazing to make me sit up.

Hope I used them right...

Thank for your help Mattias.
A.

Closed Thread