469,925 Members | 1,519 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,925 developers. It's quick & easy.

String vs. Stringbuilder speed parsing questio

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
4 1957
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
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
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
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.

Similar topics

2 posts views Thread by Zach Tong | last post: by
12 posts views Thread by Richard Lewis Haggard | last post: by
26 posts views Thread by Hardy Wang | last post: by
9 posts views Thread by Michael D. Ober | last post: by
15 posts views Thread by morleyc | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.