Sankarann
Sankarann

Reputation: 2665

String Format with numbers or Space

I am working on Simple Mask DatePicker, In that the Text is Formatted as like a Mask..

For that, am using the String formats.. My question is how to format the below code,

string.Format("{0:00-00-0000}", 2)

Output: "20-00-0000"

What i required is,

Expected: "2 - - "

And for this,

string.Format("{0:00-00-0000}", 2203)

Expected: "22-03- "

How could i format like this?

Upvotes: 3

Views: 276

Answers (1)

Chris Ballard
Chris Ballard

Reputation: 3769

Now I understand what you need (I think). Try this instead:

string.Format("{0}        ", 2).Substring(0, 8).Insert(2, "-").Insert(5, "-");

So format as number, ensure padded with relevant number of spaces, and then insert the - characters.

Upvotes: 2

Related Questions