Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ExtendedStringBuilder
- {
- private StringBuilder _stringBuilder;
- public string CurrentString
- {
- get { return _stringBuilder.ToString(); }
- }
- public int Length
- {
- get { return _stringBuilder.Length; }
- }
- public ExtendedStringBuilder()
- {
- _stringBuilder = new StringBuilder();
- }
- public ExtendedStringBuilder(int capacity)
- {
- _stringBuilder = new StringBuilder(capacity);
- }
- public ExtendedStringBuilder Append(object o)
- {
- if (o is char)
- _stringBuilder.Append((char)o);
- else if ((o as string) != null)
- _stringBuilder.Append((string)o);
- else
- _stringBuilder.Append(o);
- return this;
- }
- public static ExtendedStringBuilder operator +(ExtendedStringBuilder sb, object o)
- {
- if (o is char)
- return sb.Append((char)o);
- if ((o as string) != null)
- sb.Append((string)o);
- return sb.Append(o);
- }
- public static implicit operator string(ExtendedStringBuilder sb)
- {
- return sb.CurrentString;
- }
- public static implicit operator ExtendedStringBuilder(string s)
- {
- return new ExtendedStringBuilder().Append(s);
- }
- public override string ToString()
- {
- return CurrentString;
- }
- public string ToString(int startIndex, int length)
- {
- return _stringBuilder.ToString(startIndex, length);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement