c# how to remove text from string code example

Example 1: 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 ?

Example 2: 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 3: c# remove word from string

public static string RemoveHTML(string text)
{
    text = text.Replace(" ", " ").Replace("<br>", "\n").Replace("description", "").Replace("INFRA:CORE:", "")
        .Replace("RESERVED", "")
        .Replace(":", "")
        .Replace(";", "")
        .Replace("-0/3/0", "");
        var oRegEx = new System.Text.RegularExpressions.Regex("<[^>]+>");
        return oRegEx.Replace(text, string.Empty);
}