函数:strLeft(str,num)
用途:取指定字符串左边数num个字符,中文作为2个字符出现。
说明:如最后一个汉字取则多,不取则少,则不取,即实际取字符数为num-1个。
如字符串第一个字符为中文,且num=1,则返回空字符串
FUNCTION strLeft(str,num)
DIM p_str,p_num
p_str = ""
p_num = 0 '定义变量,标记中文为2字节时的实际字符数
IF TRIM(str)<>"" THEN
FOR i = 1 TO num
IF asc(mid(str,i,1))>255 OR ASC(mid(str,i,1))<0 THEN '判断下一个欲取的字符所占字节数
p_num = p_num + 2
Else
p_num = p_num + 1
End IF
IF p_num > num THEN EXIT FOR
NEXT
p_str = Left(str,i-1) '把i-1替换为i,则产生与“说明”中相反的情况。
END IF
strLeft=p_str
END FUNCTION
'--------------------******END******--------------------
实例:
<%
FUNCTION strLeft(str,num)
DIM p_str,p_num
p_str = ""
p_num = 0
IF TRIM(str)<>"" THEN
FOR i = 1 TO num
IF asc(mid(str,i,1))>255 OR ASC(mid(str,i,1))<0 THEN
p_num = p_num + 2
Else
p_num = p_num + 1
End IF
IF p_num > num THEN EXIT FOR
NEXT
p_str = Left(str,i-1)
END IF
strLeft=p_str
END FUNCTION
a = "爱晚cnblogs红枫"
b=strLeft(a,n)
%>
<%=b%>
n值为3时, 结果为"爱";
n值为7时, 结果为"爱晚cnb";
n值为11时,结果为"爱晚cnblogs";
n值为14时,结果为"爱晚cnblogs红".
=================
'---------------------------------------------------
'代码过滤
'---------------------------------------------------
'表单 TO HTML
Function HTMLEncode(fString)
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(10), "<BR>")
HTMLEncode = fString
End Function
'HTML TO 表单
Function TABLEEncode(fString)
fString = Replace(fString, "",CHR(13))
fString = Replace(fString, "</P><P>",CHR(10) & CHR(10))
fString = Replace(fString, "<BR>",CHR(10))
TABLEEncode = fString
End Function
'HTML代码过滤
Function FilterHTML(strToFilter)
Dim strTemp
strTemp = strToFilter
While Instr(1,strTemp,"<") AND Instr(1, strTemp, ">")
strTemp = Left(strTemp, Instr(1, strTemp, "<")-1) & Right(strTemp, Len(strTemp)-Instr(1,strTemp, ">"))
WEnd
FilterHTML = strTemp
End Function