Question about string.Format function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All:
I need an easy way to format a string.
Here is my situation:
when the user inputs a character 'A', my logic suppose adding two ##. The
expecting result is ##A.
when the user inputs two characters 'AA', my logic only needs to add one #.
The expecting result is #AA.
when the user inputs three characters 'AAA', my logic does not need to add
any #.

I am expecting the issue can be resolve easily in string.Format() function
with proper formatter. But the most of formatter I can find is relate to
numeric or datetime. I'd like to know is there formatter I can use to help me
resolve my issue.

Thanks in advance
 
Hi David,

There's actually an even easier solution...

userInput.PadLeft(3,'#');

with userInput being the string to hold "A", "AA", or "AAA"

Kind Regards,

Wouter
 
Hi David,

No need to use String.Format.

string s = GetUserInput();
s = s.PadLeft(3, '#');
 
Back
Top