c# remove char from string code example
Example 1: remove all text after string c#
string input = "text?here";
int index = input.LastIndexOf("?");
if (index > 0)
input = input.Substring(0, index);
Example 2: 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);
}
Example 3: c# remove character from string at index
string s = "This is string";
s = s.Remove(2, 1);
string s = "This is string";
s = s.Remove(2, 2);
Example 4: c# remove specific character from string
string phrase = "this is, a string with, too many commas";
phrase = phrase.Replace(",", "");
Example 5: 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);
}
}
Output
Substring: OneTwo
Example 6: remove specific character from string c#
string input = "1, 2, 55";
string[] inputSplit = input.Split(", ");