how to count length of textbox and print first 10 charcter

Posted by Shanky11 under Others on 10/15/2012 | Points: 10 | Views : 981 | Status : [Member] | Replies : 1
how to count length of textbox and print first 10 charcter enter bu user dynamicalyy




Responses

Posted by: Sourabh07 on: 10/15/2012 [Member] Starter | Points: 25

Up
0
Down
Please refer the following code to check the length of the Textbox and if it is greater than 10 characters then it will print the first 10 characters and if it is not then display the message "Textbox Length should be greater than 10 characters".

TextBox1.Text="Hello EveryOne".

Code:

int i = (TextBox1.Text.ToString().Trim()).Length;

if (i > 10)
{
string str = TextBox1.Text.ToString().Trim();

str = str.Substring(0, 10);

Response.Write(str);
}
else
Response.Write("Textbox Length should be greater than 10 characters.");

Output:
Hello Ever

Sourabh07

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response