Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     


In ASP.Net C# substring string function returns the part of a string starting from the specified starting index. It have two overloads:

1. Substring(int startIndex)

2. Substring(int startIndex, int length)

1st type of Substring overloaded function accepts only single parameter as integer type starting index of the character position in the specified string.


It will show only the loworld. hel will be removed. In this function it will remove the first 3 letters

2nd type Substring overloaded function accepts two types of parameters, first as integer type starting index of the character position in the string and second parameter as the integer type length or the number of characters to be returned as the substring of specified string.

In second type we will write

Response.Write("helloworld".Substring(0, "helloworld".Length - 3));

Now the output will come hellowo

To remove the last character from string

 public string RemoveLastString(string targetString)

return targetString.Substring(0,targetString.Length-1);

Response.Write( RemoveLastString("HelloWorld"));

Share this article   |    Print    |    Article read by 9265 times
Rohit kakria
I am software developer
Related Articles: No related article
Related Interview Questions: No related interview question