Click here to Skip to main content
12,756,298 members (34,446 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ C++/CLI string
How do i convert a char to a System::String^?

I have this:

System::String^ text;
 text = UART_WriteBuffer[UART_WriteIndexTail].ToString();

where UART_WriteBuffer is a char[] and it contains "at\r". UART_WriteIndexTail ranges from 0 to 2.

I want text to contain "a" after the conversion but it contains "97" the ASCII value of "a" represented as a string.
Posted 27-Jan-10 6:15am
Updated 27-Jan-10 6:46am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Easy way to do this is to create String^ from the character array and use the indexer on string.
String^ text = gcnew String(UART_WriteBuffer);
Now you can write text[UART_WriteIndexTail].ToString()
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If you need a single character then you may do
  System::String ^ text = gcnew String("");
  str += (wchar_t) a[0];


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170217.1 | Last Updated 27 Jan 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100