ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Join

This extension method joins the StringBuilder values

Source

public static string Join(this StringBuilder sb, string seperator)
{
    if (sb == null) return String.Empty;

    var lst = new List<string>();
    for (int i = 0; i < sb.Length; i++)
    {
        lst.Add(sb[i].ToString());
    }

    return String.Join(seperator, lst.ToArray());
}

Example

var sb1=new StringBuilder();
sb1.Append("a");
sb1.Append("b");
sb1.Append("c");

var joined1 = sb1.Join("|"); // return a|b|c

var sb2=new StringBuilder();
sb2.Append("a");

var joined2 = sb2.Join("|"); // return a

Author: Müslüm ÖZTÜRK

Submitted on: 5 sep. 2015

Language: C#

Type: StringBuilder

Views: 4922