c# remove part of string code example
Example 1: c# string remove
string myString = "Hello Grepper Developers";
string newStr = myString.Remove(5);
string newStr2 = myString.Remove(5, 8);
Example 2: 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 3: 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 4: c# remove character from string at index
remove char from an index of string