

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Replace Character in a String in Java without using replace() method
- Converting a StringBuilder to String in Java
- Java String, StringBuffer and StringBuilder Tutorial.
- Converting String to StringBuilder in Java
- 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#
- Where to use a StringBuffer/StringBuilder than a String in Java?
- Replace words of a string - JavaScript
- How to replace Digits into String using Java?
- How to replace multiple spaces in a string using a single space using Java regex?
- Replace characters in a string in Arduino
- How i can replace number with string using Python?
- Clear a StringBuilder in C#
Advertisements