ASP.Net C# Remove Characters String Function

Updated on 17 May 2012,
Published on 03 Jul 2008

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

Example 1
string strText = "C# Remove String Function";

Response.Write(strText.Remove(2));
Output

C#

Above example shows that the remove string function removed the string starting from the second (2nd) index to the end of the specified string.

Example 2
string strText = "C# Remove String Function";

Response.Write(strText.Remove(10, 7));
Output

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."

Output:

Learn with the help of live sample of C# Remove String Function from the following link:

String Remove Function

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.

4 Responses to "ASP.Net C# Remove Characters String Function"
parikshit
Great buddy

It helped me alot
the string functions are excellent with good examples

i learn a lot from this site

thanks
Rajkumaar a.
Mohit Chauhan
2011-06-01 16:08:26.123

i want to splitte this string.
plz help me
i want this result


2011-06-01
bhattji
it too easy you losers
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email