What I want to do must be easy because I can't find it on the web.
I have existing C code with char* strings all over the place. I'd like to get those strings to the Form1.h file so I can use them there. All I want is...
String^ newText;
newText = String(oldCharStarString);

But I get error C2440:
Cannot convert from 'System::String' to 'System::String^'

Why not?

Walt

hi!

try this ->

String*newText;
newText = new String(oldCharStarString);

Daniel

hi!

you can also try following:

char* ConvertString2Chars ( System::String* strValue)
{
  char* charArray = (char*) System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(strValue).ToPointer();
  return charArray;
}

///
/// convert-function (char* => String)
///
System::String* ConvertChars2String ( const char* charArray )
{
  return charArray;
}

hope this helps

Daniel,
The first suggestin worked. Thank you very much.
And thanks to DaniWeb. No where else on the web could I find the answer.
One small addition. The compiler wanted gcnew instead of new. Like this...
String*newText;
newText = gcnew String(oldCharStarString);

Walt

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.