latest Post

C# Program to Count Lines in a String

using System;

using System.Text.RegularExpressions;


class Program


{


    static void Main()


    {


        long a = countstring("This is \n mboxtuts\n Website");


        Console.WriteLine("Number of  lines in the string  is: {0}",a);


        Console.ReadLine();


    }


    static long countstring(string str)


    {


        long count = 1;


        int start = 0;


        while ((start = str.IndexOf('\n', start)) != -1)


        {


            count++;


            start++;


        }


        return count;


    }


}

-------------------------------------------------------------------

Here is the output of the C# Program:


Number of  lines in the string  is : 3

About Mallikarjun A

Mallikarjun A
Recommended Posts × +

0 comments:

Post a Comment