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...

Comments

Popular posts from this blog

SSC CGL 2016 Tier-1 Marks / Result

DATA TYPES IN C#

Pattern printing program

IS STRING MUTABLE OR IMMUTABLE IN .NET?

Top Mutual Funds

SSC CGL 2017 TIER 2 RESULT OUT

JUST IN TIME (JIT)

Can we have multiple Main methods in one class

TOP 15 VISUAL STUDIO SHORTCUT KEYS

Top 10 Interview Tips and Questions