remove a character from a string c# code example

Example 1: c# string remove

//using System;
string myString = "Hello Grepper Developers";

/*Removing all characters starting from a position*/
string newStr = myString.Remove(5);
	//remove all characters from string after position 5
	//Output: Hello

/*Removes a specified number of characters after starting from a position*/
string newStr2 = myString.Remove(5, 8); 
	//start from position 5 of string and remove next 8 characters
	//Output: Hello Developers

Example 2: c# remove specific character from string

string phrase = "this is, a string with, too many commas";
phrase = phrase.Replace(",", "");

Example 3: remove specific character from string c#

string input = "1, 2, 55";

//This will split the string for everything that is in between ", "
string[] inputSplit = input.Split(", ");

//items in inputSplit = "1" "2" "55"

Example 4: c# remove character from string at index

remove char from an index of string