Search code examples
c#stringbuilder

How to replace entire StringBuilder value?


I need to assign a new string value to completely replace the existing string value in a StringBuilder object.

But,

sb.Append() will only add to the end of a string, and sb.Insert(0,stringVal) will only add to the beginning of the string.

sb.Replace() will replace PART of the string, IF I know what part of it is to look for it.

I simply need to just replace the entire sb string value with a new value even though I do not know what the current contents of the string is.


Solution

  • sb.Clear() removes all characters from the current StringBuilder instance.