C#: How to replace string in C#

 C#     sbo     Updated on Aug 20, 2013     VIKRAM     620   

Introduction:

In this article i will explain how to Replace a string in C#.

Description:

In prevous articles i explained How to replcae string in SQL Server. Now i will explain in C#.

Example: 

string Email = "vikramreddy@gmail.com";

// Email ID before replace.
Console.WriteLine("Before Replace: " + Email);

Output:

Before Replace: vikramreddy@gmail.com

// Replace Email ID here by using Replace(char oldChar, char newChar) method.
Email = Email.Replace("@gmail.com", "@studentboxoffice.in");

// Email ID after replace.
Console.WriteLine("After Replace: " + Email);

Output:

After Replace: vikramreddy@studentboxoffice.in

Full Source Code:

class ReplaceString
    {
        public static void Main()
        {
            string Email = "vikramreddy@gmail.com";

            // Email ID before replace.
            Console.WriteLine("Before Replace: " + Email);

            // Replace Email here.
            Email = Email.Replace("@gmail.com", "@studentboxoffice.in");

            // Email ID after replace.
            Console.WriteLine("After Replace: " + Email);

            Console.ReadKey();
        }
    }

Output:

 

  Related Articles
SQL Server: Variables
SQL Server: Differences between CHAR, NCHAR, VARCHAR and NVARCHAR
SQL Server: System Databases
SQL Server: Insert values into Identity Column
ASP.Net: List View Basic Example
JQuery: How to replace string in JQuery
Java Script: How to replace string in Java Script
SQL Server: How to replace string in SQL Server
C#: How to convert string to int in C#
SQL Server: How to get fixed length number format in SQL Server (or) How to prefix zeros to number, to get fixed length number format in SQL Server
  Recent Articles
SQL Server: Variables
SQL Server: Differences between CHAR, NCHAR, VARCHAR and NVARCHAR
SQL Server: System Databases
SQL Server: Insert values into Identity Column
ASP.Net: List View Basic Example
JQuery: How to replace string in JQuery
Java Script: How to replace string in Java Script
SQL Server: How to replace string in SQL Server
C#: How to convert string to int in C#
SQL Server: How to get fixed length number format in SQL Server (or) How to prefix zeros to number, to get fixed length number format in SQL Server