Crops the string if the given size is smaller than the string length - CSharp System.IO

CSharp examples for System.IO:File Size

Description

Crops the string if the given size is smaller than the string length

Demo Code


using System.Linq;
using System.Collections.Generic;

public class Main{
        /// <summary>
        ///     Crops the string if the given size is smaller than the string length
        /// </summary>
        /// <param name="aString">the given string to be cropped</param>
        /// <param name="size">the maximum size of the string</param>
        /// <returns>the cropped string</returns>
        public static string Crop(this string aString, int size)
        {/*from   w  w w  . j a va2  s . c o m*/
            return aString.Length > size ? aString.Remove(size) : aString;
        }
}

Related Tutorials