Thursday, 25 June 2015

Write a C# program to accept string from the user and replace all occurrences of character ‘a’ by ‘*’ symbol

using System;

class pro
{
    static void Main()
    {
        String sentence;
        Console.WriteLine("Enter a string: ");
        sentence=Console.ReadLine();
        char[] letter=sentence.ToCharArray();
        for(int i=0;i<sentence.Length;i++)
        {
            if(letter[i]=='a'|| letter[i]=='A')
                letter[i]='*';
        }
        String data=new String(letter);
        Console.WriteLine(data);
    }
}

No comments:

Post a Comment