CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2007
    Posts
    609

    Get size of a StringBuilder

    I can't seem to find this info anywhere, what is the call to get the number of bytes? I know I can do ToString() and then get the number but that is quite inefficient.
    http://www.uovalor.com :: Free UO Server

  2. #2
    Join Date
    Jul 2007
    Posts
    609

    Re: Get size of a StringBuilder

    Ok I found it, it's .Length. I was trying with trial and error but I always have trouble figuring out the spelling to that word so I must have gotten it wrong. I wish they would all use Size. So much easier. lol
    http://www.uovalor.com :: Free UO Server

  3. #3
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Get size of a StringBuilder

    Yep, sometimes, Length, sometimes Size, sometimes Count and sometimes Count()...
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  4. #4
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Get size of a StringBuilder

    Maybe because count of elements in the collection cannot be neccessary same as lenght of the space allocate ;-) And Count() is the price of extension method. But despite I see the reasons, I think it could be unified.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  5. #5
    Join Date
    Apr 2011
    Posts
    3

    Re: Get size of a StringBuilder

    itn count = Encoding.ASCII.GetByteCount(string);

  6. #6
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Get size of a StringBuilder

    Yes, I think the problem is actually the English language, not the C# language.
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Get size of a StringBuilder

    Quote Originally Posted by Red Squirrel View Post
    Ok I found it, it's .Length. I was trying with trial and error but I always have trouble figuring out the spelling to that word so I must have gotten it wrong. I wish they would all use Size. So much easier. lol
    Have you heard of Msdn?

    StringBuilder class

    In Msdn, all the constructors, properties, methods, events and so on are listed for each class.

    If you are using a new class, check it out in Msdn and notice what's available - even if you don't need it this time, you might remember enough for next time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured