Char String to String ^ - Help Needed
-
I'm using Visual C++ 2005 .NET. (I'm new to .Net programming) How do you convert a char string to a String ^ for printing in RichTextBox? Thanks. This is my code which does not work.
char StringToDisplay[100] = {'\0'}; char StringToConcat[100] = {'\0'}; char chDllVersion[80]; // chDllVersion is returned from another function sprintf( StringToConcat, "dll version in use = %s ",chDllVersion); strcat( StringToDisplay, StringToConcat ); RichTextBox1->Text = StringToDisplay; // <- This gives an error because StringToDisplay Type is not of correct type
-
I'm using Visual C++ 2005 .NET. (I'm new to .Net programming) How do you convert a char string to a String ^ for printing in RichTextBox? Thanks. This is my code which does not work.
char StringToDisplay[100] = {'\0'}; char StringToConcat[100] = {'\0'}; char chDllVersion[80]; // chDllVersion is returned from another function sprintf( StringToConcat, "dll version in use = %s ",chDllVersion); strcat( StringToDisplay, StringToConcat ); RichTextBox1->Text = StringToDisplay; // <- This gives an error because StringToDisplay Type is not of correct type
if this is about C++/CLI (i.e. the managed version of C++) you should use the string type, not char arrays; and ask in the C++/CLI forum. If you're new to .NET I strongly suggest you choose, buy and study an introductory text on the language of your choice. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
I'm using Visual C++ 2005 .NET. (I'm new to .Net programming) How do you convert a char string to a String ^ for printing in RichTextBox? Thanks. This is my code which does not work.
char StringToDisplay[100] = {'\0'}; char StringToConcat[100] = {'\0'}; char chDllVersion[80]; // chDllVersion is returned from another function sprintf( StringToConcat, "dll version in use = %s ",chDllVersion); strcat( StringToDisplay, StringToConcat ); RichTextBox1->Text = StringToDisplay; // <- This gives an error because StringToDisplay Type is not of correct type
I think I found a workable solution. I would not start a new project doing it this way but I'm working with some legacy code that is unmanaged so I need to deal with char arrays as string from C. To convert from char array to String in VS C++ .Net Managed Code use:
gcnew System::String (YourCharArrayStringToDisplay);
So for example,char ThingToShow[100] sprintf( ThingToShow, "This works!"); MessageBox::Show(gcnew System::String(ThingToShow));
Here is the link that I found it in: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/adcadbc1-9092-41ba-8deb-01e800f0b172[^] :) -
I'm using Visual C++ 2005 .NET. (I'm new to .Net programming) How do you convert a char string to a String ^ for printing in RichTextBox? Thanks. This is my code which does not work.
char StringToDisplay[100] = {'\0'}; char StringToConcat[100] = {'\0'}; char chDllVersion[80]; // chDllVersion is returned from another function sprintf( StringToConcat, "dll version in use = %s ",chDllVersion); strcat( StringToDisplay, StringToConcat ); RichTextBox1->Text = StringToDisplay; // <- This gives an error because StringToDisplay Type is not of correct type
Try this code.......... This is for c# .......... RichTextBox1.Text = Convert.ToString(StringToDisplay);