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

Repeat

for Repeat String .

Source

public static class MehrdadExtensions
{
    /// <summary>
    /// Repeat String .
    /// </summary>
    /// <param name="input">String</param>
    /// <param name="number">Count Repeat </param>
    /// <param name="splitChar">caracter for Split Repeat </param>
    /// <returns></returns>
    public static string Repeat(this string input, int number, string RepeatChar)
    {
        if (!string.IsNullOrEmpty(input))
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 1; i <= number; i++)
            {
                sb.AppendFormat("{0}{1}", input, RepeatChar);
            }
            return sb.Remove(sb.Length - 1, 1).ToString();
        }
        else
        {
            return null;
        }
    }
}

Example

string name = "mehrdad";
Response.Write("Name is : " + name);
Response.Write("<br />");
Response.Write(name.Repeat(20,"-"));

Author: Mehrdad Ghasemi

Submitted on: 28 mrt. 2009

Language: C#

Type: System.String

Views: 4913