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

🙂

7 thoughts on “Get characters in a string – C Sharp/C#

  1. Andres

    Useful tips! I have been previously hunting for something like this for a long time now. Thank you!

    Reply
  2. Malik Post author

    @Andres -> Thanks for the nice comment. Keep in touch. You can expect even more! Always welcome 🙂

    Reply
  3. Malik Post author

    @Powerful Xrumer Service- >Thanks for the nice comment. Keep in touch.

    Reply
  4. Malik Post author

    @Xrumer Blast Service-> thanks for the nice comment… we will always try to give you the best we can… keep in touch… 🙂

    Reply
  5. Myriam Schnetzer

    Great review! This is exactly the type of article that needs to be shared around the web. Sad on the Yahoo for not positioning this post higher!

    Reply

Leave a Reply to Powerful Xrumer Service Cancel reply

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