Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Advertisements