
- 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
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
- Related Articles
- Python program to change character of a string using given index
- C# Program to replace a special character from a String
- C# program to remove n-th character from a string
- Java Program to Get a Character From the Given String
- Removing nth character from a string in Python program
- Python program for removing nth character from a string
- Python program for removing n-th character from a string?
- Java program for removing n-th character from a string
- C# program to replace n-th character from a given index in a string
- How to remove a particular character from a String.
- Java Program to locate a character in a string
- Java Program to access character of a string
- Python Program to Remove the nth Index Character from a Non-Empty String
- Java Program to create Character Array from String Objects
- Java program to convert a character array to string

Advertisements