How to replace string in C#?
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):
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):
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:
-
CreatedAug 20, 2013
-
UpdatedNov 03, 2020
-
Views2,337