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

String vs. Stringbuilder speed parsing questio

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

Feb 7 '06 #1
Share this Question
Share on Google+
4 Replies


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

--
Patrice

<al*****@altavista.com> a écrit dans le message de
news:11**********************@g44g2000cwa.googlegr oups.com...
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.

Feb 7 '06 #2

P: n/a
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*****@altavista.com> escribió en el mensaje
news:11**********************@g44g2000cwa.googlegr oups.com...
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.

Feb 7 '06 #3

P: n/a
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
Feb 7 '06 #4

P: n/a
Patrice, Carlos & Cor - thank you all for your comments.

Cheers,
Al.

Feb 7 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.