This approach will be applicable for any format of the Maxid String. For Example : D0001, ABC0001, 0001. It wont support,if the character is coming after number (0001D)
String id = "D0001";
GenerateID(id);
public String GenerateID(String id)
{
int pos=0;
for (int i = id.Length; i>0 ; i--)
{
if (Char.IsNumber(id[i - 1]))
{
pos = i - 1;
}
else
break;
}
return id.Substring(0, pos) + (int.Parse(id.Substring(pos, id.Length - pos)) + 1).ToString("D" + (id.Length - pos));
}
Regards,
Senthil S