469,631 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

'registering' format provider to format numbers as octal?

hi there,

I am just learning about IFormattable, ICustomFormatter, IFormatProvider and
the like...

although being a bit tricky to understand, it becomes clear after some
clicking and readying...

what is not clear to me and constitutes my question is:

I can build 'format provider' and use it with .ToString() and .Format()
methods. However, Console.WriteLine() does not allow for any 'format
provider'. Can I somehow 'create/register/hack/build' a format provider into
the runtime system (for the lifetime of my application or forever), for (for
example) applicationwide or systemwide formatting numbers as octal, so I can
use transparently the following statement:

dim n as integer = 123
System.Console.WriteLine("{0:O}", n)

which would produce "173"

or

dim n as integer = 123
System.Console.WriteLine("{0:NumberToWordsFormat}" , n)

which would produce "one hundred twenty three"

Nov 21 '05 #1
2 1419
Hi,

Why not try this.

dim n as integer = 123
System.Console.WriteLine(String.Format("{0:O}", n))

Ken
--------------------
"gjuro kladaric" <gj***@email.htnet.hr> wrote in message
news:eo**************@TK2MSFTNGP14.phx.gbl...
hi there,

I am just learning about IFormattable, ICustomFormatter, IFormatProvider
and the like...

although being a bit tricky to understand, it becomes clear after some
clicking and readying...

what is not clear to me and constitutes my question is:

I can build 'format provider' and use it with .ToString() and .Format()
methods. However, Console.WriteLine() does not allow for any 'format
provider'. Can I somehow 'create/register/hack/build' a format provider
into the runtime system (for the lifetime of my application or forever),
for (for example) applicationwide or systemwide formatting numbers as
octal, so I can use transparently the following statement:

dim n as integer = 123
System.Console.WriteLine("{0:O}", n)

which would produce "173"

or

dim n as integer = 123
System.Console.WriteLine("{0:NumberToWordsFormat}" , n)

which would produce "one hundred twenty three"

Nov 21 '05 #2
hi, ken,

thanks for the answer

however, if I understand it well, your sample would not work, unless you
supply the format provider, like this:

dim n as integer = 123
System.Console.WriteLine(String.Format(format_prov ider, "{0:O}", n))

I am aware that I can do that, and also something like:

dim mc as myClass
mc.int_var = 123
System.Console.WriteLine(mc.int_var.ToStringOctal( ))

however, my question was if I can link my format provider (for octal
representation) into .NET runtime, so that my way of octal formatting of an
integer, for eaxmple, is available everywhere where traditional formatting
is available

do you know that answer?

thanks,

gjuro
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
Hi,

Why not try this.

dim n as integer = 123
System.Console.WriteLine(String.Format("{0:O}", n))

Ken
--------------------
"gjuro kladaric" <gj***@email.htnet.hr> wrote in message
news:eo**************@TK2MSFTNGP14.phx.gbl...
hi there,

I am just learning about IFormattable, ICustomFormatter, IFormatProvider
and the like...

although being a bit tricky to understand, it becomes clear after some
clicking and readying...

what is not clear to me and constitutes my question is:

I can build 'format provider' and use it with .ToString() and .Format()
methods. However, Console.WriteLine() does not allow for any 'format
provider'. Can I somehow 'create/register/hack/build' a format provider
into the runtime system (for the lifetime of my application or forever),
for (for example) applicationwide or systemwide formatting numbers as
octal, so I can use transparently the following statement:

dim n as integer = 123
System.Console.WriteLine("{0:O}", n)

which would produce "173"

or

dim n as integer = 123
System.Console.WriteLine("{0:NumberToWordsFormat}" , n)

which would produce "one hundred twenty three"


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sverre Bakke | last post: by
9 posts views Thread by Rowan Chapman | last post: by
4 posts views Thread by Willem Broekema | last post: by
6 posts views Thread by Willem-Jan Selen | last post: by
5 posts views Thread by siliconwafer | last post: by
6 posts views Thread by Duncan Winn | last post: by
9 posts views Thread by David Rysdam | last post: by
12 posts views Thread by naunetr | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.