LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-30-2005, 07:11 AM   #1
Diederick
LQ Newbie
 
Registered: Apr 2005
Posts: 25

Rep: Reputation: 15
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
 
Old 11-30-2005, 07:48 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Couldn't you just do:
Code:
	std::string name = "Dennis";
	char letter = *(name.c_str());
 
Old 11-30-2005, 08:00 AM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
.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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cast from sting to int in Visual C++ Diederick Programming 3 11-29-2005 08:27 AM
C programming - Char to Int Conversion ? indian Programming 4 09-30-2005 08:00 AM
Sting.h alaios Programming 2 08-21-2005 04:35 AM
C programming int to char conversion paranoid times Programming 15 03-17-2005 11:06 PM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 03:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration