Answers for "remove character from string C#"


remove all text after string c#

string input = "text?here";
int index = input.LastIndexOf("?"); // Character to remove "?"
if (index > 0)
    input = input.Substring(0, index); // This will remove all text after character ?
Posted by: Guest on September-03-2020

c# remove specific character from string

string phrase = "this is, a string with, too many commas";
phrase = phrase.Replace(",", "");
Posted by: Guest on March-01-2020

c# remove character from string at index

string s = "This is string";
s = s.Remove(2, 1);
//Output: Ths is string

string s = "This is string";
s = s.Remove(2, 2);
//Output: Th is string
Posted by: Guest on July-05-2020

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
Posted by: Guest on February-06-2021

remove character from string C#

// our string
string myString = "[email protected]";

// lets remove the @ symbol
// here we replace our "@" in our string to an empty string 
string newString = myString.Replace("@", string.empty);
// output should look like this:
Posted by: Guest on August-17-2021

C# copy string except for last letter

using System;

class Program
    static void Main()
        string input = "OneTwoThree";

        string sub = input.Substring(0, input.Length - 5);
        Console.WriteLine("Substring: {0}", sub);


Substring: OneTwo
Posted by: Guest on March-23-2020

Code answers related to "remove character from string C#"

C# Answers by Framework

Browse Popular Code Answers by Language