String formatting in .NET

String formatting in .NET

Anonymous
Not applicable
1,234 Views
14 Replies
Message 1 of 15

String formatting in .NET

Anonymous
Not applicable
Ok, this is not really an acad-related issue, but i'm doing an Acad-net app,
so ....

In c++ i format at string with dynamic precision using the formatstring
"%.*f", m_sPrecision, x

How do i do that in .NET. I'm totally lost.

Or even better, (look; Acad related) can i format a string the same way as
using the %q formaters in ARX.
i.e. let Acad format the strings according to the unit-settings

/Matt
0 Likes
1,235 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable
Not sure about the C++ equivalent, but you can use
the Autodesk.AutoCAD.Runtime.Converter class in
acdbmgd.dll to convert between distance/angle and
strings.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message news:5403173@discussion.autodesk.com...
Ok, this is not really an acad-related issue, but i'm doing an Acad-net app,
so ....

In c++ i format at string with dynamic precision using the formatstring
"%.*f", m_sPrecision, x

How do i do that in .NET. I'm totally lost.

Or even better, (look; Acad related) can i format a string the same way as
using the %q formaters in ARX.
i.e. let Acad format the strings according to the unit-settings

/Matt
0 Likes
Message 3 of 15

Anonymous
Not applicable
Brilliant. Just what I wanted.

So I can fail to understand the .net string formatting for a couple of weeks
more

/Matt



"Tony Tanzillo" wrote in message
news:5403635@discussion.autodesk.com...
Not sure about the C++ equivalent, but you can use
the Autodesk.AutoCAD.Runtime.Converter class in
acdbmgd.dll to convert between distance/angle and
strings.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message
news:5403173@discussion.autodesk.com...
Ok, this is not really an acad-related issue, but i'm doing an Acad-net app,
so ....

In c++ i format at string with dynamic precision using the formatstring
"%.*f", m_sPrecision, x

How do i do that in .NET. I'm totally lost.

Or even better, (look; Acad related) can i format a string the same way as
using the %q formaters in ARX.
i.e. let Acad format the strings according to the unit-settings

/Matt
0 Likes
Message 4 of 15

Anonymous
Not applicable
.NET string formatting doesn't do angles and distances,
so unless you need the more generic conversion, its not
too helpful.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message news:5403763@discussion.autodesk.com...
Brilliant. Just what I wanted.

So I can fail to understand the .net string formatting for a couple of weeks
more

/Matt



"Tony Tanzillo" wrote in message
news:5403635@discussion.autodesk.com...
Not sure about the C++ equivalent, but you can use
the Autodesk.AutoCAD.Runtime.Converter class in
acdbmgd.dll to convert between distance/angle and
strings.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message
news:5403173@discussion.autodesk.com...
Ok, this is not really an acad-related issue, but i'm doing an Acad-net app,
so ....

In c++ i format at string with dynamic precision using the formatstring
"%.*f", m_sPrecision, x

How do i do that in .NET. I'm totally lost.

Or even better, (look; Acad related) can i format a string the same way as
using the %q formaters in ARX.
i.e. let Acad format the strings according to the unit-settings

/Matt
0 Likes
Message 5 of 15

Anonymous
Not applicable
"C# Text Manipulation Handbook - String Handling and Regular Expressions" by
Wrox is going to be helpful.

Microsoft has their hand in scientific computing now which should be
researched for sophisticated math and calculus capabilities. Quite possibly
the recent release of .NET 3.0 may have new classes for advanced
calculations.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h



"Tony Tanzillo" wrote in message
news:5404132@discussion.autodesk.com...
.NET string formatting doesn't do angles and distances,
so unless you need the more generic conversion, its not
too helpful.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message
news:5403763@discussion.autodesk.com...
Brilliant. Just what I wanted.

So I can fail to understand the .net string formatting for a couple of weeks
more

/Matt



"Tony Tanzillo" wrote in message
news:5403635@discussion.autodesk.com...
Not sure about the C++ equivalent, but you can use
the Autodesk.AutoCAD.Runtime.Converter class in
acdbmgd.dll to convert between distance/angle and
strings.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message
news:5403173@discussion.autodesk.com...
Ok, this is not really an acad-related issue, but i'm doing an Acad-net app,
so ....

In c++ i format at string with dynamic precision using the formatstring
"%.*f", m_sPrecision, x

How do i do that in .NET. I'm totally lost.

Or even better, (look; Acad related) can i format a string the same way as
using the %q formaters in ARX.
i.e. let Acad format the strings according to the unit-settings

/Matt
0 Likes
Message 6 of 15

Anonymous
Not applicable
All i really wanted was to specify the numbers of decimals dynamically.
But this was very usefull.

/Matt

"Tony Tanzillo" wrote in message
news:5404132@discussion.autodesk.com...
.NET string formatting doesn't do angles and distances,
so unless you need the more generic conversion, its not
too helpful.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message
news:5403763@discussion.autodesk.com...
Brilliant. Just what I wanted.

So I can fail to understand the .net string formatting for a couple of weeks
more

/Matt



"Tony Tanzillo" wrote in message
news:5403635@discussion.autodesk.com...
Not sure about the C++ equivalent, but you can use
the Autodesk.AutoCAD.Runtime.Converter class in
acdbmgd.dll to convert between distance/angle and
strings.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message
news:5403173@discussion.autodesk.com...
Ok, this is not really an acad-related issue, but i'm doing an Acad-net app,
so ....

In c++ i format at string with dynamic precision using the formatstring
"%.*f", m_sPrecision, x

How do i do that in .NET. I'm totally lost.

Or even better, (look; Acad related) can i format a string the same way as
using the %q formaters in ARX.
i.e. let Acad format the strings according to the unit-settings

/Matt
0 Likes
Message 7 of 15

jbooth
Advocate
Advocate
If I read the last post correctly, the solution is simpler than you would first expect. You can pass formatting arguments to the ToString() method of the Double class/datatype.

Forgive the following, as I'm more used to C# than C++:

double x = 12345.67;
string s = x.ToString("N4"); //s is now "12,345.6700"

See http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx for more info.
0 Likes
Message 8 of 15

Anonymous
Not applicable
But how do I change the 4 to a 5 depending on, for example, LUPREC ?
(ok, this has again left the autocad relationship)

On way can be to create the format string in runtime and to use that string
to format the string i wanted.
But there must be a better way! Or... ?

/Matt


wrote in message news:5404875@discussion.autodesk.com...
If I read the last post correctly, the solution is simpler than you would
first expect. You can pass formatting arguments to the ToString() method of
the Double class/datatype.

Forgive the following, as I'm more used to C# than C++:

double x = 12345.67;
string s = x.ToString("N4"); //s is now "12,345.6700"

See http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx for more info.
0 Likes
Message 9 of 15

Anonymous
Not applicable
Matt

Look at
Autodesk.AutoCAD.DatabaseServices.Database.get_Luprec()
which returns an Int32

also, Tony refered to Autodesk.AutoCAD.Runtime.Converter class in
acdbmgd.dll
.. it's actually in acmgd.dll .. but still in the Runtime Namespace so it
will still work fine as quoted. .. no biggie.

///
kwb



"Matt" wrote in message
news:5405016@discussion.autodesk.com...
But how do I change the 4 to a 5 depending on, for example, LUPREC ?
(ok, this has again left the autocad relationship)

On way can be to create the format string in runtime and to use that string
to format the string i wanted.
But there must be a better way! Or... ?

/Matt


wrote in message news:5404875@discussion.autodesk.com...
If I read the last post correctly, the solution is simpler than you would
first expect. You can pass formatting arguments to the ToString() method of
the Double class/datatype.

Forgive the following, as I'm more used to C# than C++:

double x = 12345.67;
string s = x.ToString("N4"); //s is now "12,345.6700"

See http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx for more info.
0 Likes
Message 10 of 15

Anonymous
Not applicable
You can dynamically format a numeric value by
defining a class that implements the IFormatProvider
interface, havin a GetFormat() member that returns
an instance of a NumberFormatInfo object, whose
members can specify formatting aspects such as the
number of decimal places, and so forth.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message news:5405016@discussion.autodesk.com...
But how do I change the 4 to a 5 depending on, for example, LUPREC ?
(ok, this has again left the autocad relationship)

On way can be to create the format string in runtime and to use that string
to format the string i wanted.
But there must be a better way! Or... ?

/Matt


wrote in message news:5404875@discussion.autodesk.com...
If I read the last post correctly, the solution is simpler than you would
first expect. You can pass formatting arguments to the ToString() method of
the Double class/datatype.

Forgive the following, as I'm more used to C# than C++:

double x = 12345.67;
string s = x.ToString("N4"); //s is now "12,345.6700"

See http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx for more info.
0 Likes
Message 11 of 15

Anonymous
Not applicable
The converter does the job. Noprobs.
This was just a generic question on how to use the ToString("N4"); to fit my
needs.

Case closed

/Matt



"Kerry Brown" wrote in message
news:5405026@discussion.autodesk.com...
Matt

Look at
Autodesk.AutoCAD.DatabaseServices.Database.get_Luprec()
which returns an Int32

also, Tony refered to Autodesk.AutoCAD.Runtime.Converter class in
acdbmgd.dll
.. it's actually in acmgd.dll .. but still in the Runtime Namespace so it
will still work fine as quoted. .. no biggie.

///
kwb



"Matt" wrote in message
news:5405016@discussion.autodesk.com...
But how do I change the 4 to a 5 depending on, for example, LUPREC ?
(ok, this has again left the autocad relationship)

On way can be to create the format string in runtime and to use that string
to format the string i wanted.
But there must be a better way! Or... ?

/Matt


wrote in message news:5404875@discussion.autodesk.com...
If I read the last post correctly, the solution is simpler than you would
first expect. You can pass formatting arguments to the ToString() method of
the Double class/datatype.

Forgive the following, as I'm more used to C# than C++:

double x = 12345.67;
string s = x.ToString("N4"); //s is now "12,345.6700"

See http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx for more info.
0 Likes
Message 12 of 15

Anonymous
Not applicable
I must say that printf sounds a lot more simple
But i maybee just old and grumpy

/Matt


"Tony Tanzillo" wrote in message
news:5405046@discussion.autodesk.com...
You can dynamically format a numeric value by
defining a class that implements the IFormatProvider
interface, havin a GetFormat() member that returns
an instance of a NumberFormatInfo object, whose
members can specify formatting aspects such as the
number of decimal places, and so forth.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message
news:5405016@discussion.autodesk.com...
But how do I change the 4 to a 5 depending on, for example, LUPREC ?
(ok, this has again left the autocad relationship)

On way can be to create the format string in runtime and to use that string
to format the string i wanted.
But there must be a better way! Or... ?

/Matt


wrote in message news:5404875@discussion.autodesk.com...
If I read the last post correctly, the solution is simpler than you would
first expect. You can pass formatting arguments to the ToString() method of
the Double class/datatype.

Forgive the following, as I'm more used to C# than C++:

double x = 12345.67;
string s = x.ToString("N4"); //s is now "12,345.6700"

See http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx for more info.
0 Likes
Message 13 of 15

Anonymous
Not applicable
If i unserstand it correct maybe this will help you.

int Luprec = Application.DocumentManager.MdiActiveDocument.Database.Luprec;

...

DistFPPrompt = DistFP.ToString("F" + Luprec.ToString());

DistSPPrompt = DistSP.ToString("F" + Luprec.ToString());

Dist = Math.Abs(DistSP - DistFP);

DistPrompt = Dist.ToString("F" + Luprec.ToString());

ed.WriteMessage(String.Format("\nabgewickelte Länge = {0}, erster Punkt =
{1}, zweiter Punkt = {2}", DistPrompt, DistFPPrompt, DistSPPrompt));


--
Roland Feletic
Pauser ZT-GMBH
http://www.pauser.at

hp workstation xw4200, 3GB
quadro fx1400
AutoCAD 2007, 3DSMax 8.0 SP 2
0 Likes
Message 14 of 15

Anonymous
Not applicable
printf() ?? More simple?

.NET is not simple because it utilizes an all-
inclusive approach to solving problems like
localization and so forth.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message news:5405029@discussion.autodesk.com...
I must say that printf sounds a lot more simple
But i maybee just old and grumpy

/Matt


"Tony Tanzillo" wrote in message
news:5405046@discussion.autodesk.com...
You can dynamically format a numeric value by
defining a class that implements the IFormatProvider
interface, havin a GetFormat() member that returns
an instance of a NumberFormatInfo object, whose
members can specify formatting aspects such as the
number of decimal places, and so forth.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Matt" wrote in message
news:5405016@discussion.autodesk.com...
But how do I change the 4 to a 5 depending on, for example, LUPREC ?
(ok, this has again left the autocad relationship)

On way can be to create the format string in runtime and to use that string
to format the string i wanted.
But there must be a better way! Or... ?

/Matt


wrote in message news:5404875@discussion.autodesk.com...
If I read the last post correctly, the solution is simpler than you would
first expect. You can pass formatting arguments to the ToString() method of
the Double class/datatype.

Forgive the following, as I'm more used to C# than C++:

double x = 12345.67;
string s = x.ToString("N4"); //s is now "12,345.6700"

See http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx for more info.
0 Likes
Message 15 of 15

Anonymous
Not applicable
Look at the String.Format() methods: it has the sprintf formatting strings you're looking for.

http://idunno.org/displayBlog.aspx/2004071401

Bill Daly
0 Likes