2 using System.Collections.Generic;
11 public static void Clear(
this StringBuilder sb )
25 if ( o1 == o2 )
return true;
30 if ( o1 is
string ) s1 = (string)o1;
31 else if (o1 is StringBuilder) s1 = ((StringBuilder)o1).ToString();
34 if ( o2 is
string ) s2 = (string)o2;
35 else if (o2 is StringBuilder) s2 = ((StringBuilder)o2).ToString();
48 public static StringBuilder
RemoveLast(
this StringBuilder builder,
int chars)
50 if ( builder.Length <= chars )
56 builder.Length -= chars;
67 public static void Substring(
this StringBuilder src, StringBuilder dest,
int start,
int length )
69 for (
int i = start; i < length; i++ )
82 public static StringBuilder
Substring(
this StringBuilder builder,
int start,
int length )
84 StringBuilder result =
new StringBuilder();
85 builder.Substring( start, length );
94 public static void PutTo(
this StringBuilder src, StringBuilder dest )
107 public static void PutTo(
this StringBuilder src, StringBuilder dest,
int start,
int length )
109 src.Substring( dest, start, length );
110 src.Remove( start, length );
120 public static StringBuilder
PutTo(
this StringBuilder builder,
int start,
int length )
122 StringBuilder removed = builder.Substring( start, length );
123 builder.Remove( start, length );
127 public static int IndexForWhich(
this StringBuilder builder, Predicate<char> pred )
129 for (
int i = 0; i < builder.Length; i++ )
131 if ( pred( builder[i] ) )
138 public static int IndexOf(
this StringBuilder builder,
char c )
140 return builder.IndexForWhich( ch => ch == c );
143 public static void RemoveLeading(
this StringBuilder builder, Predicate<char> pred )
146 for ( i = 0; i < builder.Length; i++ )
148 if ( !pred( builder[i] ) )
153 builder.Remove( 0, i );
156 public static void RemoveTrailing(
this StringBuilder builder, Predicate<char> pred )
159 for ( i = builder.Length - 1; i >= 0; i-- )
161 if ( !pred( builder[i] ) )
165 if (i < builder.Length - 1)
166 builder.Remove( i + 1, builder.Length - i - 1 );
169 public static void Trim(
this StringBuilder builder )
171 builder.RemoveLeading( c => Char.IsWhiteSpace( c ) );
172 builder.RemoveTrailing( c => Char.IsWhiteSpace( c ) );
175 public static void TakeFirstWord(
this StringBuilder src, StringBuilder dest )
177 int ws = src.IndexForWhich( c =>
char.IsWhiteSpace( c ) );
178 if ( ws < 0 ) src.PutTo( dest );
179 else src.PutTo( dest, 0, ws + 1 );
188 public static string Repeat(
this string s,
int times )
190 StringBuilder sb =
new StringBuilder();
192 for (
int i = 0; i < times; i++)
195 return sb.ToString();
198 public static string[]
Append(
this string s, params
object[] ends )
200 string[] results =
new string[ends.Length];
202 for (
int i = 0; i < ends.Length; i++ )
204 results[i] = s + ends[i];
static void Trim(this StringBuilder builder)
static string [] Append(this string s, params object[] ends)
static StringBuilder PutTo(this StringBuilder builder, int start, int length)
Poistaa osamerkkijonon ja palauttaa sen toisena StringBuilderina..
static void RemoveLeading(this StringBuilder builder, Predicate< char > pred)
static void RemoveTrailing(this StringBuilder builder, Predicate< char > pred)
static StringBuilder Substring(this StringBuilder builder, int start, int length)
Palauttaa osamerkkijonon toisena StringBuilderina.
static void Substring(this StringBuilder src, StringBuilder dest, int start, int length)
Kirjoittaa osamerkkijonon toiseen StringBuilderiin.
static bool StringEquals(object o1, object o2)
Vertaa kahta oliota, jotka ovat joko merkkijonoja tai StringBuildereita, merkki kerrallaan.
static StringBuilder RemoveLast(this StringBuilder builder, int chars)
Poistaa merkkijonon lopusta tietyn määrän merkkejä. Jos merkkijono on lyhyempi kuin poistettava määrä...
static int IndexForWhich(this StringBuilder builder, Predicate< char > pred)
static int IndexOf(this StringBuilder builder, char c)
static void PutTo(this StringBuilder src, StringBuilder dest)
Poistaa koko StringBuilderin sisällön ja kirjoittaa sen toiseen StringBuilderiin. ...
static void TakeFirstWord(this StringBuilder src, StringBuilder dest)
static void PutTo(this StringBuilder src, StringBuilder dest, int start, int length)
Poistaa osamerkkijonon ja kirjoittaa sen toiseen StringBuilderiin.
static string Repeat(this string s, int times)
Toistaa merkkijonon annetun määrän verran.