文件大小:1.11 KB
文件类型:rar
发布时间:2018-10-05 14:42:17
需资源分:1
下载次数:1
Tag:截取字符串
::资源简介::
CLEAR
Str1 = "123456人发可个方和方经品他三方登1山泛水多福多寿辅导费对方01234567890"
? CutStr(str1,31,0)
? CutStr(str1,31,1)
FUNCTION CutStr(cStr1,nLen1,nAdd)
LOCAL N1,cStr2
*!* 强行将参数值转换为字符串,并去掉字符串右边的空格
cStr1 = RTRIM(TRANSFORM(cStr1))
*!* 长度参数错误或者大于字符串长度,取字符串最大长度
N1 = LEN(cStr1)
nLen1 = IIF(TYPE("nLen1") # "N",N1,IIF(nLen1>N1,N1,nLen1))
*!* 截取的最后一个字符是半个双字节时,是舍去还是保留
nAdd = IIF(TYPE("nAdd") # "N",0,IIF(nAdd = 1,1,0))
if N1 > nLen1
LOCAL i,nCount
nCount = 0
*!* 计算字符是双字节还是单字节,是第1位还是第2位
FOR i=1 TO nLen1
IF ISLEADBYTE(SUBSTR(cStr1,i,1)) = .T. &&判断双字节时计数 +1
nCount = nCount + 1
ENDIF
ENDFOR
IF ISLEADBYTE(SUBSTR(cStr1,i,1)) = .T. &&判断是不是双字节
IF MOD(nCount,2)=0 &&判断是否双字节的第2位
cStr2=SUBSTR(cStr1,1,nLen1)
ELSE
cStr2=IIF(nAdd = 0,SUBSTR(cStr1,1,nLen1-1),SUBSTR(cStr1,1,nLen1+1))
ENDIF
ELSE
cStr2=SUBSTR(cStr1,1,nLen1)
ENDIF
ELSE
cStr2 = cStr1
ENDIF
RETURN cStr2
ENDFUNC
::下载地址::
>> 评论