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?

3
  • can you please show where you use the property, and how ? Commented Feb 7, 2013 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. Commented Feb 7, 2013 at 20:03
  • There you said it - you'd need to implement IFormattable yourself in order to use custom formats. See also stackoverflow.com/a/10512433/63733 Commented Feb 7, 2013 at 20:06

1 Answer 1

1

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

Well thanks. I couldn't exactly use a mask, but i created a custom attribute that does similar things. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.