3

I have the following string: "10222002750400447092095835"

I want it to be displayed like this: 10 2220 0275 0400 4470 9209 5835

I tried doing the following, with no result at all:

[DisplayFormat(DataFormatString = "{0:00 0000 0000 0000 0000 0000 0000}", ApplyFormatInEditMode = true)]

or

[DisplayFormat(DataFormatString = "{0:## #### #### #### #### #### ####}", ApplyFormatInEditMode = true)]

What am I doing wrong?

ojek
  • 9,680
  • 21
  • 71
  • 110
  • can you please show where you use the property, and how ? – Raphaël Althaus Feb 07 '13 at 20:00
  • For the case of simplicity, here: `String.Format("{0:## #### #### #### #### #### ####}", "10222002750400447092095835");`. The problem is exactly in the argument - its a string, and string is not IFormattable. But how can i omit that? This argument needs to be a string. – ojek Feb 07 '13 at 20:03
  • There you said it - you'd need to implement `IFormattable` yourself in order to use custom formats. See also http://stackoverflow.com/a/10512433/63733 – marapet Feb 07 '13 at 20:06

1 Answers1

1

I believe what you are looking for is String masking. See below.

Stackoverflow - How to mask a string Stackoverflow - Apply mask to string

Community
  • 1
  • 1
James Shaw
  • 839
  • 1
  • 6
  • 16
  • Well thanks. I couldn't exactly use a mask, but i created a custom attribute that does similar things. :) – ojek Feb 07 '13 at 20:34