ASP.Net C# Substring String Function

Updated on 17 May 2012,
Published on 30 Jun 2008

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

Ouput:

You can learn more about C# Substring function from the sample below:

String Substring Function

Continue to next tutorial ASP.Net C# Split String Function to learn how to split the string into a string array collection.

Welite - Responsive Personal WordPress Blog Theme
9 Responses to "ASP.Net C# Substring String Function"
Thanks for nice tutorial. Teaching method was simple and best.
posubabu
Yaa It's a Good One.and Simple Very Easy to Understand
sidheshawr
It is very nice and easy to understand.
Anonymous
depiction has made it easy to get, thanks
somalingapalem
It gives a good idea about substring,its very nice and easily understand.
kapil
It's Good...........
nick
brilliant !!!! This helps me a lot!
ranjan
its very easy to understand.... :)
Sahithi
Teaching method is so simple and understandable to everyone.Font is also looking good.
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email