473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

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

Jan 23 '06 #1
2 1120
> I have heard a lot about intern string - so I wanted to use them to
increas e speed of processing.
I think you could gain more by using a StringBuilder when recreating
the stirng instead of the += operator.

String.Intern(s)

in an effort in incrase spped of processing. My question is though -
am I using intern string correctly?


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.
Jan 23 '06 #2

Mattias Sjögren wrote:
I have heard a lot about intern string - so I wanted to use them to
increas e speed of processing.


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


Thanks. I'll try this and see does it imporve speed of processing.
String.Intern(s)

in an effort in incrase spped of processing. My question is though -
am I using intern string correctly?


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


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

Hope I used them right...

Thank for your help Mattias.
A.

Jan 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alistair | last post by:
I should just get a hat with a big D on it and then everyone would recognise me.. anyway... I have a DB full of people and their details.. I'm trying to perform a query based on age. so...
3
by: Steve | last post by:
Hi all I am using the following code to draw strings onto a Form: ---------------------------- Dim tabGraphics As System.Drawing.Graphics = Me.CreateGraphics() Dim labelFont As New...
5
by: Charles Law | last post by:
Hi folks Not really a .NET question, but I always think this is a good place to ask. Does anyone have a favourite algorithm for determining the similarity of, or difference between two...
7
by: MeganTSU | last post by:
Hey yall! I am trying to get this program finished for class.... It says that you are suppposed to write a program that will display a check formatted out put (the output looks like a check). I got...
9
by: Diane | last post by:
Could you please explain me how can I output nested strings? Here is an example: "adsd{rfkm}xcv" The output should start from the inner parentheses, such as: dfF rfkm
5
by: Twinkle | last post by:
HI guys i have two strings .in first string a word file is there and the second string a html file is there.now i want to compare to both string if some word missing in second string then it...
16
by: InDepth | last post by:
Now that .NET is at it's fourth release (3.5 is coming soon), my very humble question to the gurus is: "What have we won with the decision to have string objects immutable? Or did we won?" ...
4
sumittyagi
by: sumittyagi | last post by:
Hi All! I am confused in the functioning of String.intern() function. public class StringTest { public static void main(String args) { String test2 = new String("ABC");...
19
by: bowlderyu | last post by:
Hello, all. If a struct contains a character strings, there are two methods to define the struct, one by character array, another by character pointer. E.g, //Program for struct includeing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.