How can i convert Ascii to CString

How can i convert Ascii (represented as UINT) to CString ?
netformxAsked:
Who is Participating?
 
rajeev_devinConnect With a Mentor Commented:
Try this way
UNIT c = 'g';
CString str(c);

If it does not work then try this
UNIT c = 'g';
CString str((char)c); // explicitly typecase UINNT to char.
0
 
rajeev_devinCommented:
>> Ascii (represented as UINT)
By the way ASCII is represtented as char.
Then also it will like this

unsigned int c = 'a';
CString str;
str += c;

If you find it is char the simply replace
unsigned int c = 'a';
with
unsigned int c = 'a';
0
 
netformxAuthor Commented:
in this case the method parameter is UINT nChar, this nChar value is 103 (for 'g') and not 'g' itself.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
rajeev_devinCommented:
Is the solution working ?
0
 
rajeev_devinCommented:
>> in this case the method parameter is UINT nChar, this nChar value is 103 (for 'g') and not 'g' itself.
for a 4 byte UINT. Only the last byte is used if you are storing char.
0
 
rajeev_devinCommented:
Let me take your case then
UNIT c = 'g';
...


CString str;
str = c;  // c will be converted to char, and then assigned to str.
 
0
 
netformxAuthor Commented:
hi rageev,

when compiling this code:
UINT nChar = 103;
CString str = nChar;

i get an error (on the line -> CString str = nChar;)
 : error C2440: 'initializing' : cannot convert from 'UINT' to 'ATL::CStringT<BaseType,StringTraits>'

i'm working with visual studio 2005
0
 
netformxAuthor Commented:
second solution worked :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.