Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1619
  • Last Modified:

How can i convert Ascii to CString

How can i convert Ascii (represented as UINT) to CString ?
0
netformx
Asked:
netformx
  • 5
  • 3
1 Solution
 
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
 
rajeev_devinCommented:
Is the solution working ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
rajeev_devinCommented:
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
 
netformxAuthor Commented:
second solution worked :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now