Get characters in a string – C Sharp/C#

By | April 7, 2012

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

🙂

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Reply

Your email address will not be published. Required fields are marked *