关闭

全角转换为半角

标签: cbuttondeletebytenull
804人阅读 评论(0) 收藏 举报
void __fastcall tform1::button1click(tobject *sender)
{
        int nlength=edit1->text.length();
        if (nlength==0)
                return;
        ansistring str="";
        char *ctmp=new char[nlength+1];
        strpcopy(ctmp,edit1->text);
        byte c1,c2;
        int i;
        for (i=0;i<nlength;i++)
        {
                c1=ctmp[i];
                c2=ctmp[i+1];
                if (c1==163)//判断是否为全角字符
                {

                        str=str+ansistring((char)(c2-128));
                        i++;
                        continue;
                 }
                if (c1>163)//判断是否为文字
                {

                        str=str+ansistring((char)c1);
                        str=str+ansistring((char)c2);
                        i++;
                        continue;
                }
                if ((c1==161) && (c2==161))//全角空格是个特例,另加处理
                        {
                                str=str+" ";
                                i++;
                                continue;
                        }
                str=str+ ansistring(char(c1));
        }
        edit2->text=str;
        delete ctmp;ctmp=null;
} 
 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:260146次
    • 积分:3040
    • 等级:
    • 排名:第11928名
    • 原创:34篇
    • 转载:116篇
    • 译文:0篇
    • 评论:60条
    最新评论