Solved

Convert Unmanaged char to magaged string (String ^ ) in VC++. Net

Posted on 2010-09-10
6
1,146 Views
Last Modified: 2012-05-10
Hi,

I would like to convert unmanaged char to managed string in VC++ .net. I was able to convert char * to String^ using the below statement ,however I was not able to convert char to String^.

String ^ CXMLUtil::ConvertChartoString(const char *ch)
{
      String ^ strValue=gcnew String(ch);
      return strValue;
}

Please let me know how to convert unmanaged char to managed string String^.

Thanks
0
Comment
Question by:GouthamAnand
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33648230
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33648246
0
 

Author Comment

by:GouthamAnand
ID: 33648590
Hi ,

After including the code suggested by you, I got another error saying "Error      224      error C4980: '__box' : use of this keyword requires /clr:oldSyntax command line option". I dont want to change the command line to /clr:oldSyntax.

Please advise me.      
0
Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33648801
Use something else. Convert, ASCIIEncoding, ...  Can you show your code?
Simple constructor? That's from Unciode:
String^ szGreekAlpha = gcnew String( L'\x0319',5 );
http://msdn.microsoft.com/en-us/library/xsa4321w.aspx





0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 125 total points
ID: 33664399
           wchar_t ch = 'x';
            String^ s = gcnew String(&ch);
and
            char c = 'y';
            String^ s2 = gcnew String(&c);


For both narrow and wide characters.  (Note the & - it won't compile without that for single characters)
0
 

Author Closing Comment

by:GouthamAnand
ID: 33977505
Thank you.
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question