473,387 Members | 1,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

String::Format problem

I spent many hours on this, googling around and experimenting, and still
nothing.

I wrote an umanaged program (actually various classes), while I was
developing them I used command line to test it.
Now, I decided to make GUI for it, so I created new project: "Windows Forms
Application (.NET)" (I was trying to use something that's not managed (e.g.
MFC, but I learned quickly that I don't actually know how to use MFC :)
In .NET I was able to quickly create the GUI that looked as I wanted it too
look.

Now my problem is really silly. While I figured out how to convert
System::String to for example std::string, and looks like the other way
around is actually easy, I can't for a love of God make String::Format do
what I want.
Even the examples from MSDN doesn't work when I copy&paste them verbatim!
Here is an example:
http://msdn2.microsoft.com/en-us/library/fht0f5be.aspx

In a simple program that has just textbox, button and label, the following
code works:
label1->Text = String::Format("Hello, {0}", textBox1->Text);

But this, doesn't want to:
label1->Text = String::Format("Hello, {0}", 10);

My goal is basically do something like this:
unsigned short int pc = 8000;
label1->Text = String::Format("Address: {0,4:X}", pc);

Anyone has idea what I'm doing wrong?

I have also an unrelated question: If I have a managed class (for the
form), and I define inside a pointer to an unmanaged class, is that a good
practice? Right now it appears to work fine, but before I had an exception
that the pointer is null (even though I did new on the form's load, and
pointer was used after selecting an option from a menu). I have no idea how
I even fixed it.

Thanks for help.
--
ダレック
Aug 30 '07 #1
3 2119
My goal is basically do something like this:
unsigned short int pc = 8000;
label1->Text = String::Format("Address: {0,4:X}", pc);
Would this be sufficient for you?
label1->Text = "Address: " + pc.ToString("X4");
>
Anyone has idea what I'm doing wrong?

I have also an unrelated question: If I have a managed class (for the
form), and I define inside a pointer to an unmanaged class, is that a good
practice? Right now it appears to work fine, but before I had an exception
that the pointer is null (even though I did new on the form's load, and
pointer was used after selecting an option from a menu). I have no idea
how
I even fixed it.
That is the right way to use native classes from managed code. Often, you
create a managed class to wrap each native object, and its only
responsibility is taking care of that one native pointer.
>
Thanks for help.
--
????

Aug 30 '07 #2

[snip]
Maybe there's some option enabled in my VC++ (it is from VS 2003), but
which option is responsible for that?
[snip]
I'm really wondering what's wrong with my C++ compiler. Even examples on
MSDN webpage didn't work.
You need an upgrade to VC 2005, even Express Edition will work. Managed
Extensions for C++ that came with VC 2003 were so full of problems that
Microsoft started over in VC 2005, giving us the C++/CLI language.
Sep 4 '07 #3
On Tue, 4 Sep 2007 11:13:07 -0500, Ben Voigt [C++ MVP] wrote:
You need an upgrade to VC 2005, even Express Edition will work. Managed
Extensions for C++ that came with VC 2003 were so full of problems that
Microsoft started over in VC 2005, giving us the C++/CLI language.
Actually one of the readers here (I don't know if he wants me to mention
his name since he answered privately) pointed me to use a __box() around
basic types like integers etc. which seems to do the thing. I can put char*
in String() and it seems to solve most of the problems.
He also recommended me to switch to VS 2005, and I'll try it as soon as I
can.

Anyway, thank you Ben for troubleshooting the problem, I really appreciate
that you tried to help.
I have another question about creating virtual listbox, but I'll create
another thread for it, since it is unrelated.

--
ダレック
Sep 6 '07 #4

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

Similar topics

7
by: Roger Helliwell | last post by:
Hello Everyone, Has anyone found a quick reference for the many string formatting options for string.Format() ? I'm spending a ridiculous amount of time trying to write one line of code that...
5
by: raffelm | last post by:
I'm struggling to find a way to include long path names in a command line argument string that I have to build at runtime. I need to create a string like -o:"c:\my documents\my file.txt". ...
3
by: Boz | last post by:
Hi, I am trying to use string.Format() to output the value of a double. double da = 100000000000.99994; double db = 100000000000.9994; double dc = 100000000000.994; double dd =...
2
by: Bob | last post by:
I'm having trouble the string.Format() throwing exceptions and I can't figure out what I am doing wrong. Given the following setup code: string str = { "one", "two", "three", "four" }; double...
2
by: Akeel | last post by:
Hi I have the following code char splitter={','}; string fields=row.ToString().Split(splitter) string serviceDefintion="" // row.ToString().Split(splitter // conatins the followin...
11
by: Matt | last post by:
string format formula to write a text file below is not working for me pos 1 to 10 name pos 15 to 30 lastname pos 45 to 75 job Adam smith programmer string fmt = "{1,10}{15-30}{45,75}"...
8
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to...
1
by: Derek =?utf-8?Q?Kuli=C5=84ski?= / takeda | last post by:
I spent many hours on this, googling around and experimenting, and still nothing. I wrote an umanaged program (actually various classes), while I was developing them I used command line to test...
8
by: Armando Rocha | last post by:
Hi, Hi have a string with 16 chars "25DD68EDEB8D5E11" and i want show it in form like this "25DD-68ED-EB8D-5E11", i try String.Format("{0:####-####-####-####}", mystr), but not work, i think...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.