Click here to Skip to main content
15,169,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if (a == string.Empty)

               NO = "EN0001";

               int i = Convert.ToInt32(a.Substring(2, 4));
               i += 1;
               no = i;
               NO = "EN" + a.Substring(2, 4 - i.ToString().Length) + i;

           return NO;

ia have error that"
Index and length must refer to a location within the string.
Parameter name: length

" please any one can help me please,

1 solution

You need to check the length of the string in a before you start using Substring: if it only has three characters for example, you code will fail with the error you are getting.
try this:
if (a == string.Empty)
if (string.IsNullOrWhiteSpace(a) || a.Length < 6)

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