# AppendText() vs. BuildSnippet()

Source: https://developer.codestencil.com/scenario-based-examples/appendtext-vs-buildsnippet

AppendText Method

Purpose: Adds text to the ExpandedText StringBuilder object.

  
Overloads:  
AppendText(): Clears the ExpandedText.  
AppendText(string text, string linefeed): Adds a string to ExpandedText, followed by a linefeed (default is \\n).  
AppendText(List&lt;string&gt; list, string indent): Adds each string in the list to ExpandedText, each preceded by the specified indent.  
AppendText(string text, int indent): Adds a string to ExpandedText, each line indented by the specified number of spaces, followed by a linefeed.  
AppendText(string text, int indent, string linefeed): Similar to the previous, but with a specified linefeed character.  
AppendText(string text, string indent, string linefeed): Adds a string to ExpandedText, where each line is indented with the specified indent string and ends with the specified linefeed.

BuildSnippet Method  
Purpose: Manages the \_snippet StringBuilder object, which is private and seems to serve a different or more specific purpose compared to ExpandedText.  
Overloads:  
BuildSnippet(string text, int indent, bool noCarriage): Adds text to \_snippet, with an option to omit the carriage return (line break).  
BuildSnippet(StringBuilder stringsBuilder, string text, int indent, bool noCarriage): Adds text to a specified StringBuilder, allowing more flexibility and control over where the text is appended.  
BuildSnippet(bool canClear): Either clears \_snippet or returns its current value based on the canClear flag.  
BuildSnippet(List&lt;string&gt; list, int indent): Adds each string in the list to \_snippet, each indented by the specified amount.  
Key Differences  
Target StringBuilder: AppendText operates on the public ExpandedText StringBuilder, while BuildSnippet manages a private \_snippet StringBuilder.  
Use Case: AppendText seems designed for building a larger body of text (like code or documentation) in a structured format, while BuildSnippet appears to be for constructing smaller, more specific text segments or code snippets.  
Flexibility: BuildSnippet provides overloads that allow for a more nuanced handling of the text, such as omitting the carriage return and working with different StringBuilder instances.  
In summary, AppendText is primarily used for appending formatted text to a public StringBuilder (ExpandedText), potentially for larger or more general content. In contrast, BuildSnippet is used for building or manipulating smaller snippets of text in a private StringBuilder (\_snippet), allowing for more specific text formatting and handling.
