Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Friday 10 March 2017

String based program


String program #1 (Length of string)

Enter a string: liveviar
Length of string: 8

The program for the string program is written in C# programming language and will accept a string as input. The loops will iterate based on the string of entry.
 
String based program

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code the program.

Practical Implementation:

using System;

namespace patternProblem.String
{
    class String1     //find length of string
    {
        static void Main(string[] args)
        {
            Console.Write("Enter a string: ");
            string str = Console.ReadLine();
            int count = 0;

            //Method-1 (Using in-built length property)
            Console.WriteLine("Length of string: {0}", str.Length);

            //Method-2 (Using foreach loop)
            foreach (char c in str)
            {
                count++;
            }
            Console.WriteLine("Length of string: {0}", count);                      
           
            Console.ReadKey();
        }
    }
}

Output:
The input string here is liveviar. So, the length of string is 8. The output is shown below:

Enter a string: liveviar
Length of string: 8
Press any key to continue . . .


For any query, comment us below.

Skip to Main Table String based program

Previous - Formula based program #11


Click imagination hunt to read latest blogs.


Keep learning and sharing...

No comments:

Post a Comment

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...