473,594 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'registering' format provider to format numbers as octal?

hi there,

I am just learning about IFormattable, ICustomFormatte r, 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.WriteLi ne() 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:N umberToWordsFor mat}", n)

which would produce "one hundred twenty three"

Nov 21 '05 #1
2 1563
Hi,

Why not try this.

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

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

I am just learning about IFormattable, ICustomFormatte r, 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.WriteLi ne() 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:N umberToWordsFor mat}", 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(Strin g.Format(format _provider, "{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.in t_var.ToStringO ctal())

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***@bellsout h.net> wrote in message
news:Ox******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

Why not try this.

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

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

I am just learning about IFormattable, ICustomFormatte r, 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.WriteLi ne() 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:N umberToWordsFor mat}", n)

which would produce "one hundred twenty three"


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3203
by: Sverre Bakke | last post by:
Hi I am using the base_convert() function to convert numbers between binary, hexadecimal, decimal, etc... It works great, but I have problems converting numbers with .'s Like this number: 15.20 decimal will be 1111 as binary...
9
10421
by: Rowan Chapman | last post by:
Hey all! I'm kinda new to VB but not to programin'. So I know what it is like when you are asked trivial questions. Could some1 please tell me what the syntax would be 2 only allow numerical data into a textbox. thankz in advanced -Ro -------------------------------------------------------------------- " Reality is an illusion caused by lack of alcohol. " --------------------------------------------------------------------
4
1706
by: Willem Broekema | last post by:
To me, it seems there are some irregularities in how literal numbers are interpreted. As you know, Python allows integer literals in three bases: "11" -> (decimal) 11 "011" -> octal 11 = 9 "0x11" -> hex 11 = 17 Now for complex integers:
6
4219
by: Willem-Jan Selen | last post by:
Hie everybody, I have a problem with the following, I have a table with a row containing numbers with 2 decimal places. I want to count the sum of these numbers but my valuw returned is far to high. I think the SUM string doesn't look at the decimal place. The same is with the AVG string
5
2456
by: siliconwafer | last post by:
Hi All, What does a 'format specifier' do? Suppose I do, int a = 43; //decimal number printf("%x",a); I will get hex equivalent of 43. Does the format specifier do an implicit "decimal to hex" conversion before displaying ? Is it true for all format specifier? -Siliconwafer
1
851
by: Stan | last post by:
The convert method allows us to change any base number (bin, octal, hex ) to decimal, but how can I change a decimal value back to an octal number??? Thanks in advance Stan
6
14109
by: Duncan Winn | last post by:
I have written an Ole Db provider. It seems to be registered in the Operating system to a degree, but not fully, i.e. I can access it from a client that I have written. But it does not appear in Database Explorer's list of viable Ole Db drivers... Any suggestions??
9
9998
by: David Rysdam | last post by:
I have a large amount of data that I copy in and out of Sybase very often. Now I also want to copy this data in and out of postgres. I have an existing script that creates the entire database(s) from scratch in Sybase and then uses the Sybase bulk copy tool "bcp" to copy the data in. I already did a brute force port of this script to postgres once, but I'm trying to do it more elegantly now that I know what issues I'm going to run...
12
3549
by: naunetr | last post by:
in program below #include <stdio.h> int main() { int id = 123, io = 0123, ih = 0x123; long ld = 1234567L, lo = 01234567l, lh = 0X1234567L; float f = 123.456f; double d = 01234.56789L;
0
7946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7876
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
6654
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3859
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3897
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2385
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1210
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.