2

I'm having a problem with converting LPCSTR to System::String^, though i am able to convert System::String to LPCSTR with Marshal.

But how can i convert LPCSTR to System::String^

Thank You

Miguel P
  • 1,262
  • 6
  • 23
  • 48
  • possible duplicate of [What is the best way to convert between char* and System::String in C++/CLI](http://stackoverflow.com/questions/56561/what-is-the-best-way-to-convert-between-char-and-systemstring-in-c-cli) – Viktor Latypov Jul 27 '12 at 21:05

1 Answers1

7
gcnew System::String(lpcstrThing);
MikeP
  • 7,829
  • 33
  • 34
  • Actually, yes. Do you really want complexities in such a simple operation ? – Viktor Latypov Jul 27 '12 at 21:06
  • The `String` class has a constructor that accepts `char*` input, which copies the data up to the first null character it finds. If the data is not null-terminated, or if you know the data length ahead of time, you can use a different constructor: `gcnew System::String(lpcstrThing, 0, length);` ` – Remy Lebeau Jul 27 '12 at 21:06