
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Replace a string using StringBuilder
Set a String −
StringBuilder str = new StringBuilder("Fitness is important");
Use the Replace() method to replace a string −
str.Replace("important", "essential");
The following is the code to replace a string using StringBuilder −
Example
using System; using System.Text; class Demo { static void Main() { // Initial String StringBuilder str = new StringBuilder("Fitness is important"); Console.WriteLine(str.ToString()); // Replace str.Replace("important", "essential"); // New String Console.WriteLine(str.ToString()); Console.ReadLine(); } }
Output
Fitness is important Fitness is essential
- Related Articles
- Replace Character in a String in Java without using replace() method
- Converting a StringBuilder to String in Java
- Converting String to StringBuilder in Java
- Java String, StringBuffer and StringBuilder Tutorial.
- How to replace string using JavaScript RegExp?
- How to replace all dots in a string using JavaScript?
- Remove the whitespaces from a string using replace() in JavaScript?
- Difference between String and StringBuilder in C#
- How to replace Digits into String using Java?
- Where to use a StringBuffer/StringBuilder than a String in Java?
- How to replace multiple spaces in a string using a single space using Java regex?
- How i can replace number with string using Python?
- Replace All Consonants with Nearest Vowels In a String using C++ program
- Replace words of a string - JavaScript
- How to replace a part of the string (domain name after @) using MySQL?

Advertisements