How do I replace a text in a string?

Category: System, viewed: 879 time(s).

An example for showing how to replace a portion of text in the string.

using System;
using System.Text;

namespace Kodecsharp.Example.System
{
    public class ReplaceText
    {
        public static void Main(string[] args)
        {
            //
            // Replacing a portion of string with another text.
            //
            string text = "A, B, C, D, E, F, G, H, I, J";
            text = text.Replace(",", "");
            Console.WriteLine(text);

            //
            // Replacing a specified text of a string with another text.
            //
            StringBuilder builder = new StringBuilder("Email: @EMAIL@");
            builder.Replace("@EMAIL@", "someone@somewhere.com");
            Console.WriteLine(builder.ToString());

            Console.ReadLine();
        }
    }
}
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Our Friends

Statistics

Locations of visitors to this page