ASP.Net C# Remove Characters String Function
In ASP.Net 2.0 C#, there is a string function Remove that provides the functionality to remove the set of characters or substrings very easily and quickly. C# remove string function removes the part of a string based on the starting index or the combination of start index and the number of characters to remove. C# Remove function can be applied only to the values of string data type. Following are the two types of overloads of C# remove string function:
1. public string Remove(int startIndex);
2. public string Remove(int startIndex, int count);
String Functions Examples:
You can see the live samples and examples of String functions from the following links:
First C# remove string overloaded function accepts 1 parameter of integer type as start index of the part the string you want to remove. It removes the substring of the specified string starting from the start index parameter passed to the C# remove function. Second C# remove string overloaded function accepts 2 parameters of integer type. First parameter takes the value of start index and the second parameter accepts the count value as the number of characters to be removed from the specified string.
Example of ASP.Net C# Remove Characters String Function
string strText = "C# Remove String Function"; Response.Write(strText.Remove(2));
Above example shows that the remove string function removed the string starting from the second (2nd) index to the end of the specified string.
string strText = "C# Remove String Function"; Response.Write(strText.Remove(10, 7));
C# Remove Function
Above example shows that the C# remove string function takes two parameters as start Index = 10 and count = 7. It removes the part of string as a substring of length equal to 7 starting from 10th index of the targeted specified string.
Don't pass the index or count outside the limits of specified string otherwise it will throw an exception of: "Index and count must refer to a location within the string."
Continue to the next tutorial: ASP.Net C# Replace String Function to learn how to replace the old string pattern with new string pattern from the specified string.