VC语言

本类阅读TOP10

·VC++ 学习笔记(二)
·用Visual C++打造IE浏览器(1)
·每个开发人员现在应该下载的十种必备工具
·教你用VC6做QQ对对碰外挂程序
·Netmsg 局域网聊天程序
·Windows消息大全
·VC++下使用ADO编写数据库程序
·VC++学习笔记(四)
·非法探取密码的原理及其防范
·怎样在VC++中访问、修改注册表

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
VC里面如何拆分含汉字与字母的字符串

作者:未知 来源:月光软件站 加入时间:2005-5-13 月光软件站

给别人的程序打补丁,出现了需要拆分含汉字,字母的字符串的情况,到网上搜到的都是同一段代码

"************* 截取字符串 **************
Function InterceptString(txt,length)
txt=trim(txt)
x = len(txt)
y = 0
if x >= 1 then
for ii = 1 to x
if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then "如果是汉字
y = y + 2
else
y = y + 1
end if
if y >= length then 
txt = left(trim(txt),ii) "字符串限长
exit for
end if
next
InterceptString = txt
else
InterceptString = ""
end if
End Function 

结果就是测试有些情况下拆分出现乱码,郁闷了好半天,终于发现是网上的这段到处转贴的代码是有错误的,其实这个错误很简单的,就是因为自己没有仔细检查一下就用结果,^_^,这次偶给更正了,希望以后看到的人不会郁闷了.

void CAaaView::OnButton1()
{
 // TODO: Add your control notification handler code here
 CString ChargeItemName;
 CString aa = "9494858受得失测试585858585888d888888888888888";
 int len=0;
 ChargeItemName=InterceptString(len,aa);
 AfxMessageBox(ChargeItemName);               

 len=ChargeItemName.GetLength();
 ChargeItemName=aa.Mid(len); 
 AfxMessageBox(ChargeItemName);
}
CString CAaaView::InterceptString(int qlen, CString strSource)
{
 int len,i,y;
 CString sTemp,sreturn,ceshi;

 strSource.TrimLeft();strSource.TrimRight();
 len=strSource.GetLength();
 y=0;
 sTemp=strSource.Right(len-qlen); 
 
 for(i=0;i<len;i++)
 {
  if(sTemp[y]<0 || sTemp[y]>255)
   y=y+2;
  else
   y=y+1;
  if(y>=26)
   break;
 }
 ceshi.Format("%d",y);
 AfxMessageBox(ceshi);
 sreturn=sTemp.Left(y);

 return sreturn;
}




相关文章

相关软件