The Substring method is used to extract the characters from any part of the string.The syntax is
Substring( start_position, num_of_chars_to_grab )
Example:
Substring(0,2)
0 is the starting index of the string
2 is the length or number of characters to be grab or extract.
Example to extract characters form a string using Textbox,Label and Button.
protected void Button1_Click(object sender, EventArgs e)
{
string a = TextBox1.Text.ToString();
string b = a.Substring(2, 2); //Extract 2 characters start from the 2 index position
Label1.Text = b.ToString();
}

No comments:
Post a Comment