
- 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 replace n-th character from a given index in a string
Firstly, set a string.
string str1 = "Port"; Console.WriteLine("Original String: "+str1);
Now convert the string into character array.
char[] ch = str1.ToCharArray();
Set the character you want to replace with the index of the location. To set a character at position 3rd.
ch[2] = 'F';
To remove nth character from a string, try the following C# code. Here, we are replacing the first character.
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { string str1 = "Port"; Console.WriteLine("Original String: "+str1); char[] ch = str1.ToCharArray(); ch[0] = 'F'; string str2 = new string (ch); Console.WriteLine("New String: "+str2); } }
Output
Original String: Port New String: Fort
- Related Articles
- C# program to remove n-th 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 a special character from a String
- Java Program to replace all occurrences of a given character in a string
- Java Program to Replace a Character at a Specific Index
- C++ Program to Replace a Character at a Specific Index
- Golang program to replace a character at a specific index
- Python program to change character of a string using given index
- Java Program to Get a Character From the Given String
- C program to replace all occurrence of a character in a string
- Python Program to Remove the nth Index Character from a Non-Empty String
- Java Program to replace all occurrences of a given character with new character
- Java Program to Replace the Spaces of a String with a Specific Character
- Golang program to replace the spaces of string with a specific character

Advertisements