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
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
0 comments:
Post a Comment