1

I have a field EmpID (textbox) where user manually enters a 6 digit code. If he enters less than 6 digit then we need to add "0" as prefix to make it a 6 digit code. Example if enters 123, we must make it 000123. If he enters 1234, we must make it 001234.

I want an efficient way for handling this situation. I want to avoid writing multiple if statements. Any better way of doing this?

Zakir HC
  • 262
  • 2
  • 4
  • 18

2 Answers2

4

It's as simple as this:

tbValue = tbValue.PadLeft(6, '0');
rory.ap
  • 34,009
  • 10
  • 83
  • 174
3

You can do this using PadLeft function as below

myString = myString.PadLeft(6, '0');
Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44