C#: How to Read characters from String

 C#     sbo     Updated on Aug 30, 2013     VIKRAM     460   

Introduction:

In this article i will explain how to read characters from string in C#

Description:

In previous articles i explained How to replace string in C#, How to convert string to int in C#. In this article i will explain how to read characters from string in C#.

Example:

string Email = "vikram";

Now read all characters from Email.

// insert all characters into  Array.
var characters = Email.ToCharArray();

Now display each character from characters array in new line by using foreach.

foreach (char c in characters)
{
    // Display character by character.
    Console.WriteLine(" " + c + "\n");
}

Full Source Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpArticles
{
    class ReadCharacterByCharacter
    {
        public static void Main()
        {
            string Email = "vikram";
            // insert all characters into  Array.
            var characters = Email.ToCharArray();
            Console.WriteLine(" Characters: ");
            foreach (char c in characters)
            {
                // Display character by character.
                Console.WriteLine(" " + c + "\n");
            }
            Console.ReadLine();
        }
    }
}

Output:

  Related Articles
The major features added in C# in each release
C# Coding Standards and Naming Conventions
ASP.Net: ListView Basics - ItemEditing, ItemUpdating and ItemCanceling events
C#: How to Query for characters in a string using LinQ.
Access Specifiers or Access Modifiers in C#
  Recent Articles
The major features added in C# in each release
C# Coding Standards and Naming Conventions
ASP.Net: ListView Basics - ItemEditing, ItemUpdating and ItemCanceling events
C#: How to Query for characters in a string using LinQ.
Access Specifiers or Access Modifiers in C#