Count Lines In String

image_pdfimage_print
   
 

//The MIT License (MIT)
//http://arolibraries.codeplex.com/license
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AroLibraries.ExtensionMethods.Strings
{
    public static class StringExt
    {
        public static int Ext_CountLinesInString(this string str)
        {
            if (str == null) throw new ArgumentNullException("String is NULL");

            int counter = 1;
            string[] strTemp = str.Split(new string[] { "
" }, StringSplitOptions.None);
            if (strTemp.Length > 0)
            {
                counter = strTemp.Length;
            }
            return counter;
        }

    }
}

   
     


This entry was posted in Data Types. Bookmark the permalink.