Thread: StringBuilder

  1. #1
    Registered User C of Green's Avatar
    Join Date
    Jan 2002
    Location
    Calgary/Canada
    Posts
    59

    StringBuilder

    Hello all ... i have a StringBuilder question. Im wondering the best way
    to go about "clearing" a StringBuilder after is has aready been appended to.

    heres the deal ... i have a textBox that i regurgitate ASCII information onto
    from a StreamReader. This textBox is on a form, and on this form i have a
    "Clear" button that essentially clears the textBox ...

    Code:
    
    	StringBuilder buffer = new StringBuilder();
    
    
            private void buttonClear_Click(object sender, EventArgs e)
            {
                outputFileTextBox.Text = "";
            }
    So ... if i want to clear the StringBuilder's "buffer" that already has "x"
    amount of bytes "appened" to it, and clear the textBox at the same time ... would this
    be the worst/best way to do to do it ... or would there be a better way, other then
    allocating another builder for the next read?


    Code:
    
    	StringBuilder buffer = new StringBuilder();
    
    
            private void buttonClear_Click(object sender, EventArgs e)
            {
                outputFileTextBox.Text = "";
                buffer = new StringBuilder();
    
            }
    Any info would be great !


  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Check the StringBuilder reference for a Clear() method, or check the documentation of the Length property to see if setting it truncates. If it does, setting it to 0 would erase the contents.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading Process Memory
    By polydegmon in forum C# Programming
    Replies: 0
    Last Post: 05-26-2009, 07:18 AM
  2. C# call Delphi DLL Error.
    By sergioms in forum C# Programming
    Replies: 14
    Last Post: 12-03-2008, 09:09 AM
  3. Having a problem with string, not sure where to look
    By CompiledMonkey in forum C++ Programming
    Replies: 30
    Last Post: 11-26-2005, 06:47 PM
  4. When exactly should a StringBuilder be used?
    By gicio in forum C# Programming
    Replies: 1
    Last Post: 11-08-2003, 04:25 AM