January 28, 2016
How to Replace a String in C#/CSharp
To replace a string in C#/CSharp, we make use Replace method. Example is given below.
using System;
using System.IO;
namespace Hello_World
{
class Program
{
static void Main(string[] args)
{
string hello = "Hello World";
string myString = hello.Replace("World", "FWait");
Console.WriteLine(myString);
}
}
}
using System;
using System.IO;
namespace Hello_World
{
class Program
{
static void Main(string[] args)
{
string hello = "Hello World";
string myString = hello.Replace("World", "FWait");
Console.WriteLine(myString);
}
}
}
using System; using System.IO; namespace Hello_World { class Program { static void Main(string[] args) { string hello = "Hello World"; string myString = hello.Replace("World", "FWait"); Console.WriteLine(myString); } } }