Formatting strings
November 15, 2006 5:36 AM
Subscribe
String manipulation in C#: I know that the String.Format method can format numeric data so that {0:#,###} transforms 1234 into the string "1,234". There are lots of standard formatters like {0:C} for currency, and endless ways to format DateTime objects. But is there a similar shorthand to format a string or to apply a mask to it?
I have a db table that contains ISBN values (look at the bar code on any book and you will see the value I am talking about). It is stored in the db as a char(10), since by definition an ISBN-10 is always 10 characters. But the formatting of an isbn is always n-nnn-nnnnn-n. The final character is sometimes a letter, so just using {0:#-###-#####-#} to format the display will not work. I know I can parse it out by using substrings ("{0}-{1}-{2}-{3}", value.Substring(0,1), value.Substring(1,3), etc.), but that seems awfully verbose. Is there a shorthand method that I am missing?
posted by Lokheed to computers & internet (3 comments total)
posted by pjern at 6:26 AM on November 15, 2006