Help with Conversion from Sting to Char
Im working in Visual Studie.NET in Visual C++, and I want to convert my sting into a chat, i want just the first letter of the sting to be my char:
String *name = "Dennis"; now I want the 'D' from Dennis to be in my char letter; variable. Without the error: possible loss of data. My Code at this stage is: String *name = "Dennis"; String *firstLetter = name->Substring(0,1); char letter = System::Convert::ToChar(firstLetter); but I keep on getting "possible los of data" error. Please help. Thank you - Diederick |
Couldn't you just do:
Code:
std::string name = "Dennis"; |
.Net is Unicode compatible
Hi,
The .NET framework used multi-byte characters. In short you need to use the .NET wrapper class Char (note the capitalised C) rather than the C++ type char. The .NET multi-byte character is equivalent to the C++ wchar_t or wide character. I don't know if there is a conversion from Unicode (multi-byte character) to ANSI (single byte character) but if all you require is to grab the first character then Char should be sufficient and you program will support I18n - or at least not break from it at that point ;). graeme. |
All times are GMT -5. The time now is 03:49 AM. |