Click here to Skip to main content
15,888,610 members
Articles / Programming Languages / C#

StringBuilderPlus Improves Upon StringBuilder

Rate me:
Please Sign up or sign in to vote.
4.85/5 (62 votes)
1 Jun 2011CPOL9 min read 142.6K   807   88  
StringBuilderPlus facilitates prefixing and suffixing strings and StringBuilderPluses in an efficient manner.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Zigrem.Text
{
	public partial class StringBuilderPlus
	{

		/// <summary>
		/// Simple class to wrap a plain string.
		/// </summary>
		private class PlainString : IString
		{

			#region Static Variables

			/// <summary>
			/// PlainString's version of string.Emtpy.
			/// </summary>
			public static readonly PlainString Empty;

			#endregion


			#region Variables

			private string stringValue;

			#endregion


			#region Properties

			/// <summary>
			/// The value stored by this plain string.
			/// </summary>
			private string StringValue
			{
				get
				{
					return this.stringValue;
				}
				set
				{
					this.stringValue = value;
				}
			}


			/// <summary>
			/// The length of this string.
			/// </summary>
			public int Length
			{
				get
				{
					return this.StringValue.Length;
				}
			}

			#endregion


			#region Constructors

			/// <summary>
			/// Create a plain string from a normal string.
			/// </summary>
			/// <param name="str">The string to wrap.</param>
			public PlainString(string str)
			{
				this.StringValue = str;
			}


			/// <summary>
			/// Static constructor.
			/// </summary>
			static PlainString()
			{
				Empty = new PlainString(string.Empty);
			}

			#endregion


			#region Methods

			/// <summary>
			/// Appends the string stored by this plain string to the specified string builder.
			/// </summary>
			/// <param name="builder">The string builder to append to.</param>
			public void AppendTo(StringBuilder builder)
			{
				builder.Append(this.StringValue);
			}

			#endregion

		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States

  • Managing Your JavaScript Library in ASP.NET (if you work with ASP.net and you don't read that, you are dead to me).
  • Graduated summa cum laude with a BS in Computer Science.
  • Wrote some articles and some tips.
  • DDR ("New high score? What does that mean? Did I break it?"), ping pong, and volleyball enthusiast.
  • Software I have donated to (you should too):

Comments and Discussions