latest Post

Number of lines in the string program in c# .net

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;
    }
}


About Mallikarjun A

Mallikarjun A
Recommended Posts × +

0 comments:

Post a Comment