How to Remove a Character from a String at Specified Position in C# – Programming, Pseudocode Example, C# Programming Example
C# C# Console

How to Remove a Character from a String at Specified Position in C#

String remove character

The following asp.net c# example code demonstrate us how can we remove a specified character from a string object programmatically at run time in an asp.net application. .Net framework’s String Class String.Remove(Inte32, Int32) overloaded method allow us to remove specified number of characters at starting a specified index position from a string instance.

So, if we want to remove a specified character from a specified index position of a string, we need to set the number of characters to remove to 1 (one). And we also need to pass the index value of the specified character to Remove() method.

Such as, if we want to remove the 5th character of a string, we should pass the parameters to Remove() method as Remove(4,1), because string contain zero-based index. Here, first parameter represent the index of specified character to begin removing and second parameter represent the number of characters to remove from beginning index position.

Finally, we can call the Remove() method to remove a single character from a string object as String.Remove(SpecifiedCharacterIndex, 1).

C# Code:

Output:

How to Remove a Character from a String at Specified Position in C#
How to Remove a Character from a String at Specified Position in C#

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.