Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-10
6
Medium Priority
?
1,147 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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
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 375 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

722 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