How to Replace a Character With Another Character in a String in C#?

You are currently viewing How to Replace a Character With Another Character in a String in C#?

How to replace a character with another character in a string in C#?

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            String str1;
            String str2;

            Console.Write("Enter String : ");
            str1 = Console.ReadLine();
            
            str2 = str1.Replace('i','I');
            
            Console.WriteLine("String after replace method : " + str2);
        }
    }
}

Output

Enter String : This is india
String after replace method : ThIs Is IndIa

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply