Quantcast
Channel: CoderzHeaven » ASP.NET
Viewing all articles
Browse latest Browse all 10

Get characters in a string – C Sharp/C#

$
0
0

Hi,

Sometimes you may need to get all the characters in a string using C Sharp/C#. The following code gives you an example of how to get or display all the characters of a given string.

using System;

class MainClass
{

  public static void Main()
  {
    string sampleString= "I Love Coding";


    for (int num = 0; num < sampleString.Length; num++)
    {
      Console.WriteLine("sampleString[" + num + "] = " + sampleString[num]);
    }

  }

}

Output:
sampleString[0] = I
sampleString[1] =
sampleString[2] = L
sampleString[3] = o
sampleString[4] = v
sampleString[5] = e
sampleString[6] =
sampleString[7] = C
sampleString[8] = o
sampleString[9] = d
sampleString[10] = i
sampleString[11] = n
sampleString[12] = g
:)


Viewing all articles
Browse latest Browse all 10

Trending Articles