In ASP.Net C# substring string function returns the part of a string starting from the specified starting index of character position to the specified length of the provided string. C# substring function has 2 overloads as follows:
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. 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.
String Functions Examples:
You can see the live samples and examples of String functions from the following links:
Example of ASP.Net C# Substring String Function
Example 1
- string strText = "C# substring function";
- Response.Write(strText.Substring(3));
Output
substring function
In above example of C# substring functions starting from 0 as the index of first character of the string you will get the substring starting from start index 3 as following:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| C | # | S | u | b | s | t | r | i | n | g | f | u | n | c | t | i | o | n |
Example 2
- string strText = "C# substring function";
- Response.Write(strText.Substring(3, 9));
Output
substring
In the above example starting from the 0 as the index of first character of string you will get the substring starting from index number 3 with length of 9 characters as following:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| C | # | S | u | b | s | t | r | i | n | g | f | u | n | c | t | i | o | n | ||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Output:
You can learn more about C# Substring function from the sample below:
String Substring Function
Comments
Post a Comment