Substring
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.
Response.Write("helloworld".Substring(3))
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); }
Page_Load() { Response.Write( RemoveLastString("HelloWorld")); }
http://
http://
Contributed by:
Rohit kakria
I am software developer
Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=147
Click here to go on website
|