|
-
February 3rd, 2009, 02:59 AM
#1
Unicode string (japanese) to ANSI
Hi,
I have written a C++ console app using VS2005 which has these two lines.
CString csSrc = _T("C:\\管理者"); // Japanese characters
char* pDst = T2A(csSrc);
when I run this program and watch the values during debugging, pDst shows "C:\管ç*者".
what am I missing here ?
what changes should I make so that pDst points to "C:\\管理者".
Thanks in advance.
-
February 3rd, 2009, 03:31 AM
#2
Re: Unicode string (japanese) to ANSI
Hi,
As I understand it, "C:\\管理者". will be a double-byte string however it is represented (Unicode, MBCS, etc.), there is no codepage where you can map these characters to single-bytes.
So, you can't really get char *pDst to point to "C:\\管理者" and see it like that in the debugger.
Can you explain more about what you're trying to do?
Depending on what you want to do, the answer is maybe to define pDst as TCHAR. Alternatively, you can get the string buffer using scSrc.GetBuffer(), and work on the raw bytes if that's what you're trying to do.
Alan
-
February 3rd, 2009, 05:04 AM
#3
Re: Unicode string (japanese) to ANSI
Thanks for the reply.
here is the use case,
I need to pass "管理者" which is stored in a CString to an API ( third party library)which takes char* as the input.
Any ideas ?
-
February 3rd, 2009, 05:15 AM
#4
Re: Unicode string (japanese) to ANSI
You need to change them into proper type before doing so
Checkout APIs for string conversion Multibyte string to ANSI as well as ANSItoMUltibyte
-
February 3rd, 2009, 05:21 AM
#5
Re: Unicode string (japanese) to ANSI
Hi,
Sorry, I don't have an idea for that, I can't see how the library can handle Japanese characters if it only accepts a char*. Maybe you can get a unicode version of the library?
Alan
-
February 3rd, 2009, 10:20 AM
#6
Re: Unicode string (japanese) to ANSI
Using extended characters in string literals isn't a good idea: http://www.codeguru.com/forum/showpo...8&postcount=14
>> to an API ( third party library) which takes char* as the input.
If the API doesn't accept UTF8 encoded strings, or a string using code page 932 (Shift-JIS) - then you're out of luck.
gg
-
February 5th, 2009, 05:34 AM
#7
Re: Unicode string (japanese) to ANSI
Thanks for the reply guys.
How do I convert a wide char string to UTF8 format ?
Any links would be helpful.
-
February 5th, 2009, 08:22 AM
#8
Re: Unicode string (japanese) to ANSI
You use MultiByteToWideChar() to go from CodePage char string, or UTF8 char string, to UTF16LE wchar_t string.
You use WideCharToMultiByte() to go from wchar_t string to CodePage or UTF8 char string.
Sample code: http://www.codeguru.com/forum/showpo...1&postcount=11
When calling wstr_to_str(), pass in CP_UTF8 to convert to UTF8.
gg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|