Gets the line break total in String. - CSharp System

CSharp examples for System:String Format

Description

Gets the line break total in String.

Demo Code


using System.Globalization;

public class Main{
        /// <summary>
        /// Gets the line break total.
        /// </summary>
        /// <param name="value">The string to count line-breaks.</param>
        /// <returns>Total line-breaks.</returns>
        public static int GetLineBreakTotal(this string value)
        {//  w  w  w . j  a va2  s .co m
            return value.Count("\n") + 1;
        }
        /// <summary>
        /// Counts the specified text.
        /// </summary>
        /// <param name="value">The string contains text to count.</param>
        /// <param name="countText">The text to count.</param>
        /// <returns>The number of text to count occurring in string.</returns>
        public static int Count(this string value, string countText)
        {
            return (value.Length - value.Replace(countText, string.Empty).Length) / countText.Length;
        }
}

Related Tutorials