Gets the first characters from a given string. - CSharp System

CSharp examples for System:Char

Description

Gets the first characters from a given string.

Demo Code

//     TelerikAcademy.com. All rights reserved.
using System.Text.RegularExpressions;
using System.Text;
using System.Security.Cryptography;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System;//w ww  . ja v a 2 s .  c om

public class Main{
        /// <summary>
        /// Gets the first characters from a given string.
        /// </summary>
        /// <param name="input">Input string.</param>
        /// <param name="charsCount">Characters number count.</param>
        /// <returns>Return the given input string with the characters selected count.</returns>
        public static string GetFirstCharacters(this string input, int charsCount)
        {
            return input.Substring(0, Math.Min(input.Length, charsCount));
        }
}

Related Tutorials