iu_81的专栏

黄云万里动风色,白波九道流雪山

全角转换为半角

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;
} 
 
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭