Click here to Skip to main content
12,249,797 members (49,524 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 5:15am
Edited 27-Jan-10 5: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];
Smile | :)

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
Web02 | 2.8.160426.1 | Last Updated 27 Jan 2010
Copyright © CodeProject, 1999-2016
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