You can use RegEx for this:
var parts = Regex.Split(textBox1.Text, "(\\d+)"); textBox1.Text = parts.Length<2 ? parts[0] : parts[0] + parts[1].PadLeft(5, '0'); Update: if you don't want to use Regex, you can try the following code:
int i = 0; for(;i < textBox1.TextLength; i++){ if(char.IsDigit(textBox1.Text[i])) break; } textBox1.Text = textBox1.Text.Substring(0,i) + textBox1.Text.Substring(i).PadLeft(5,'0');