- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to change a character from a string
Let's say our string is −
StringBuilder str = new StringBuilder(); str.Append("pre");
To change a character, set the value at that particular index. The following sets a character at the 3rd position −
str[2] = 'o';
Here is the complete code −
Example
using System; using System.Text; public class Demo { public static void Main() { StringBuilder str = new StringBuilder(); str.Append("pre"); Console.WriteLine("String : "+str); Console.WriteLine("Change 3rd character"); str[2] = 'o'; Console.WriteLine("New String : "+str); } }
Output
String : pre Change 3rd character New String : pro
Advertisements