Solved

How do I convert 'CString' to 'System::String ^'

Posted on 2006-10-24
4
2,889 Views
Last Modified: 2007-12-19
I'm trying to slowly convert my MFC code to .NET code. My example works fine until I try and use a CString.

Is there a way to do this?

Thanks
0
Comment
Question by:BrianM_AZ
[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
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 17796902
What exactly do you whant to know? How to use String^ in pure managed code, or how to convert CString <-> String^ in mixed managed/unmanaged code?
0
 

Author Comment

by:BrianM_AZ
ID: 17797039
It's mixed Managed/Unmanaged code. I think I've found it...

CString sStr = "This is a test string";
String ^teststring = gcnew String(str);
.
.
.
delete teststring;

Let me know if there's a better way,
Thanks
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17797074
Yes, this is OK. To make CString from String, use CString constructor:

String ^teststring = L"This is a test string";
CString sStr(testing);
0
 

Author Comment

by:BrianM_AZ
ID: 17797126
Thanks for the help!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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