String vs. Stringbuilder speed parsing questio

  • Thread starter Thread starter almurph
  • Start date Start date
A

almurph

Hi everyone,


Can you help me please? Say you have hashtable of about 500 key/value
pairs. This hashtable has to parse a word. If the word matches the key
the then said word must be replaced by the value.
My question is though - would parsing occur faster if the word is
input as a type string or a type stringbuilder? Do you see my point?
Would appreciate any comments/experiences/suggestions that anyone has
on this one...

Al.
 
Your best bet is to test. StringBuilder are faster if you have significants
processing to do on a string and/or if those strings are big.

Here I don't really see what you mean (do you mean you would use
stringbuilders as keys instead of strings hoping it would speed up data
retrieval, if yes IMO you won't see any difference). For a start you can try
to time your code to see what is the slowest part...
 
Hi Al,

The hash table is fine with String. The StringBuilder is mostly used to
build strings concatenating small strings many times or replacing/inserting
text inside a large string, so you have to see if this fits in your problem,
which surely does for replacing the words by the new ones in the paragraph
that you want to process.


--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
 
Al,

A string is an immutable string of characters
A stringbuilder is a muttable string of characters. Therefore it needs at
least instructions to set it to an immutable string of charaters that you
probably need. (ToString)

Cor
 
Back
Top