Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to limit the data to the first 5000 characters.

VB
PostData = TextBox2.Text.Substring(0, 5000)


Getting an Error:

"Index and length must refer to a location within the string.
Parameter name: length "
Posted

This happens when the length of textbox2 value is less than 5000, try this:
C#
String PostData = TextBox2.Text;
if (PostData.Length > 5000){
    PostData = PostData.Substring(0,5000);
}
 
Share this answer
 
or it could be like this in one line :
string PostData = (TextBox2.Text.Length > 5000 ? TextBox2.Text.Substring(0, 5000) : TextBox2.Text);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900