Generate a string by duplicating a char. - CSharp System

CSharp examples for System:Char

Description

Generate a string by duplicating a char.

Demo Code


using Microsoft.Win32;
using System.Text;
using System.IO;/*  w  ww .  ja v  a 2s .  c  om*/
using System;

public class Main{
        /// <summary>
        /// Generate a string by duplicating <see cref="char"/> xch.
        /// </summary>
        /// <param name="len">duplicate times.</param>
        /// <param name="xch">the duplicated character.</param>
        /// <returns></returns>
        public static string GenStr(int len, char xch)
        {
            char[] ch = new char[len];
            for (int i = 0; i<len; i++)
            {
                ch[i] = xch;
            }
            return new string(ch);
        }
}

Related Tutorials