LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Help with Conversion from Sting to Char (https://www.linuxquestions.org/questions/programming-9/help-with-conversion-from-sting-to-char-387866/)

Diederick 11-30-2005 07:11 AM

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

dmail 11-30-2005 07:48 AM

Couldn't you just do:
Code:

        std::string name = "Dennis";
        char letter = *(name.c_str());


graemef 11-30-2005 08:00 AM

.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.