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

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
BrianM_AZAsked:
Who is Participating?
 
AlexFMConnect With a Mentor Commented:
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
 
BrianM_AZAuthor Commented:
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
 
AlexFMCommented:
Yes, this is OK. To make CString from String, use CString constructor:

String ^teststring = L"This is a test string";
CString sStr(testing);
0
 
BrianM_AZAuthor Commented:
Thanks for the help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.