唐吉诃德

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  5 Posts :: 75 Stories :: 3 Comments :: 0 Trackbacks

常用链接

留言簿(2)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

1.半角转换为全角

CString CTestExcelChange091230Dlg::DbcToSbc(CString stringText)
{
 CString str=L"";

 int nLength=stringText.GetLength();
 ASSERT(nLength!=0);
 TCHAR *c=new TCHAR[sizeof(TCHAR)*nLength+1];
 memset(c,0,sizeof(TCHAR)*nLength+1);
 wcscpy(c,stringText);
 for (int i=0;i<nLength;i++)
 {
  if (c[i]==32)
  
   c[i]=(TCHAR)12288;
   continue;
  }
   if (c[i]<127)
  {
   c[i]=(TCHAR)(c[i]+65248);
  }

 }

 str.Format(L"%s",c);

 delete c;
 c=NULL;
 return str; 
}

2.全角转换为半角

CString CSpss::SbcToDbc(CString stringText)
{
 CString str=L"";

 int nLength=stringText.GetLength();
 ASSERT(nLength!=0);
 TCHAR *c=new TCHAR[sizeof(TCHAR)*nLength+1];
 memset(c,0,sizeof(TCHAR)*nLength+1);
 wcscpy(c,stringText);
 for (int i=0;i<nLength;i++)
 {
  if (c[i]==12288)
  { c[i]=(TCHAR)32;
  continue;
  }
  if (c[i]>65280 && c[i]<65375)
   c[i]=(TCHAR)(c[i]-65248);
 }

 str.Format(L"%s",c);

 delete c;
 c=NULL;
 return str; 
}

 

这段程序今天看来有许多不好的地方,现将第一个程序其改为如下:

void CTestDlg2008Dlg::DbcToSbc(const CString stringText,CString &str)
{
 int nLength=stringText.GetLength();
 ASSERT(nLength!=0);
 TCHAR *c=new TCHAR[sizeof(TCHAR)*nLength+1];
 memset(c,0,sizeof(TCHAR)*nLength+1);
 wcscpy(c,stringText);
 for (int i=0;i<nLength;i++)
 {
  if (c[i]==32)
  {
   c[i]=(TCHAR)12288;
   continue;
  }
  if (c[i]<127)
  {
   c[i]=(TCHAR)(c[i]+65248);
  }

 }

 str.Format(L"%s",c);

 delete []c;
 c=NULL;
}
2010.7.3

 

 

posted on 2011-05-04 16:41 心羽 阅读(1282) 评论(0)  编辑 收藏 引用 所属分类: 编码

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理