怎样把双字节的字符串转化成单字节的字符串?

sunht 2001-12-28 08:59:58
如题,谢谢
...全文
350 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwwsq 2001-12-28
  • 打赏
  • 举报
回复
Unicode and MBCS Provide Portability
With MFC version 3.0 and later, MFC, including CString, is enabled for both Unicode and Multibyte Character Sets (MBCS). This support makes it easier for you to write portable applications that you can build for either Unicode or ANSI characters. To enable this portability, each character in a CString object is of type TCHAR, which is defined as wchar_t if you define the symbol _UNICODE when you build your application, or as char if not. A wchar_t character is 16 bits wide. (Unicode is available only under Windows NT.) MBCS is enabled if you build with the symbol _MBCS defined. MFC itself is built with either the _MBCS symbol (for the NAFX libraries) or the _UNICODE symbol (for the UAFX libraries) defined.

Note The CString examples in this and the accompanying articles on strings show literal strings properly formatted for Unicode portability, using the _T macro, which translates the literal string to the form

L"literal string"

which the compiler treats as a Unicode string. For example, the following code:

CString strName = _T("Name");

is translated as a Unicode string if _UNICODE is defined or as an ANSI string if not. For more information, see the article Strings: Unicode and Multibyte Character Set (MBCS) Support.

A CString object can store up to INT_MAX (2,147,483,647) characters. The TCHAR data type is used to get or set individual characters inside a CString object. Unlike character arrays, the CString class has a built-in memory allocation capability. This allows CString objects to automatically grow as needed (that is, you don’t have to worry about growing a CString object to fit longer strings).

wwwsq 2001-12-28
  • 打赏
  • 举报
回复
好像CString可以自动处理吧?

另外,野蛮一点的可以用memcpy()
florist2000 2001-12-28
  • 打赏
  • 举报
回复
WideCharToMultiByte
freeflyingqq 2001-12-28
  • 打赏
  • 举报
回复
#include "atlbase.h"
在函数中
USES_CONVERSION;
S=W2A(B);
(S是胆子节字符串指针,B是双字节字符串指针)
Peter_Sun 2001-12-28
  • 打赏
  • 举报
回复
For Example:
unsigned short a;
unsigned char b,c;
b=a/256; //High
c=a%256; //low
山中涛大爷 2001-12-28
  • 打赏
  • 举报
回复
USES_CONVERSION;
S=OLE2T(B);
或者用WideCharToMultiByte
xxyueyue 2001-12-28
  • 打赏
  • 举报
回复
好像挺不錯的

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧