Simple String.Format method question

  • Thread starter Thread starter Burak
  • Start date Start date
B

Burak

Hello,

I would like to format the string "11304200" into
"11-3042.00".

Can I do this with String.Format method? I have not come across any good
documentation.

Thank you,

Burak
 
AFAIK, you can't with String.Format.

Try...

s = "11304200"
s = s.Substring(0, 2) & "-" & s.Substring(2, 4) & "." s.Substring(6)

That what you are looking for?

Mythran
 
Hi Mythran,

You bring me back to the basics, that is the way I was always doing this
kind of things and now I try to look for things as format, while your code
is in my opinion perfect. (documentates as well very good).

Cor
 
Burak,
For documentation on what is allowed & how to use String.Format see:

http://msdn.microsoft.com/library/d...y/en-us/cpguide/html/cpconformattingtypes.asp

As you can tell from the above link, .NET does not allow custom formatting
of strings, as does custom formatting of strings really make sense? In cases
where custom formatting of strings does make sense (such as data entry) you
may be able to create a Custom Formatter object (implement the
ICustomFormatter & IFormatProvider interfaces)
http://msdn.microsoft.com/library/d...tml/frlrfsystemicustomformatterclasstopic.asp
that uses the other string methods to reformat you string.

If your string is truly a number, you might be able to convert it into a
number first then apply one of the above custom numeric formats to the
string.

Hope this helps
Jay
 
After reading your reply, I noticed an error in my original code...missing an
ampersand :P

s = s.Substring(0, 2) & "-" & s.Substring(2, 4) & "." & s.Substring(6)

Before the last s.Substring(6) :)

Mythran
 
Back
Top