Q:

Write a program in C# Sharp to find the length of a string without using library function

0

Write a program in C# Sharp to find the length of a string without using library function.

Test Data :
Input the string : nerdutella.com
Expected Output :

Length of the string is : 12 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;  
public class Exercise2
{  
    public static void Main() 
{
    string str; /* Declares a string of size 100 */
    int l= 0;
      Console.Write("\n\nFind the length of a string :\n");
      Console.Write("---------------------------------\n"); 	
      Console.Write("Input the string : ");
      str = Console.ReadLine();
         foreach(char chr in str)
        {
            l += 1;
        }

   Console.Write("Length of the string is : {0}\n\n", l);
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now