/* * Script Name: Script - Full2Half(string in_str,integer iflag) * Description: 用于全角,半角互相转换的函数 * Arguments: string strInfo //需要转换的字符串 int iFlag // 1-全角-》半角 2-半角》全角 * Returns: string * Author: Date: 2009-02-26 09:08:58 */ string ls_str // in_str =in_str2 string c_return="" long l0,l1,l2,l3,l4,i,c_leng,l_asc i=1 c_leng=len(in_str) do while i<=c_leng if iflag=1 then //1-全角-》半角 if asc(mid(in_str,1,1))=163 and asc(mid(in_str,2,1))>=161 and asc(mid(in_str,2,1))<=254 then ls_str = mid(in_str,1,2) ls_str = char(asc(mid(ls_str,2,1)) - 128) in_str = mid(in_str,3) i=i+2 else ls_str = mid(in_str,1,1) in_str = mid(in_str,2) i++ end if c_return = c_return +ls_str end if if iflag=2 then//2-半角》全角 l_asc=asc(in_str) if l_asc<=128 then if l_asc>=33 and l_asc<=126 then l1=int((l_asc+41856)/(16*16*16)) l0=mod((l_asc+41856),(16*16*16)) l2=int(l0/(16*16)) l0=mod(l0,(16*16)) l3=int(l0/16) l4=mod(l0,16) c_return=c_return+char(l1*16+l2)+char(l3*16+l4) else c_return=c_return+left(in_str,1) end if in_str=replace(in_str,1,1,"") i=i+1 else c_return=c_return+left(in_str,2) in_str=replace(in_str,1,2,"") i=i+2 end if end if loop return c_return Technorati 标签: PB, PowerBuilder, 全角, 半角互相转换的函数