StringBuilder vs. String.Concat 
Author Message
 StringBuilder vs. String.Concat

Hello, I cannot understand which method is more efficient (considering
memory usage and speed):

a) string s = String.Concat ("Kkkk","lll","lll",...)

or

b) string s = Stringbuilder.Append ("..")..

Thank you for help

Simone,
Varese - ITALY



Sun, 21 Nov 2004 17:11:35 GMT  
 StringBuilder vs. String.Concat
For up to 4 parameters first is more efficient, becouse
it's done without additional temporary objects
(stringbuilder). More than 4 - second is best becouse it
will use single allocation ( and you can specify minimum
buffer length explicitely).
Quote:
>a) string s = String.Concat ("Kkkk","lll","lll",...)

>or

>b) string s = Stringbuilder.Append ("..")..

>Thank you for help

>Simone,
>Varese - ITALY
>.



Sun, 21 Nov 2004 17:37:01 GMT  
 StringBuilder vs. String.Concat
Hello Varese,

The String is faster, however it needs more memory. Since it need create a
new object each time you modify it. On the other hand, the StringBuilder
needs less memory but more time. In general, it is suggested to use String
class if you don't modify the string very frequently or the string is not
very long. However, if you want a mutable sequence of characters (such as
for Interop with unmanaged code), the StringBuilder is necessary.

I hope this information is helpful.

Best regards,

Lion Shi, MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
reserved.
--------------------

    Newsgroups: microsoft.public.dotnet.languages.CSharp
    Subject: StringBuilder vs. String.Concat
    Date: 5 Jun 2002 02:11:35 -0700
    Organization: http://groups.google.com/
    Lines: 13

    NNTP-Posting-Host: 194.185.48.6
    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: 8bit
    X-Trace: posting.google.com 1023268295 24941 127.0.0.1 (5 Jun 2002
09:11:35 GMT)

    NNTP-Posting-Date: 5 Jun 2002 09:11:35 GMT
    Path:
cpmsftngxa08!tkmsftngp01!newsfeed00.sul.t-online.de!t-online.de!news-spur1.m
axwell.syr.edu!news.maxwell.syr.edu!netnews.com!isdnet!sn-xit-02!supernews.c
om!postnews1.google.com!not-for-mail
    Xref: cpmsftngxa08 microsoft.public.dotnet.languages.csharp:65706
    X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

    Hello, I cannot understand which method is more efficient (considering
    memory usage and speed):

    a) string s = String.Concat ("Kkkk","lll","lll",...)

    or

    b) string s = Stringbuilder.Append ("..")..

    Thank you for help

    Simone,
    Varese - ITALY



Mon, 22 Nov 2004 17:53:58 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. StringBuilder vs String

2. StringBuilder Replace vs Append Speed

3. help: textBox vs. StringBuilder in a callback function

4. Problem with URI and String Concat

5. String* Concat

6. a C question, concat two strings!!!

7. concat a string

8. concat a string

9. MFC, String Concat (???)

10. concat string only up to 128 char???

11. System::String/StringBuilder as out parameter

12. String functions or using Regular Expressions or StringBuilder

 

 
Powered by phpBB® Forum Software