Function: strleft (STR, num)
Purpose: return the number of num characters on the left of the specified string. The Chinese character is used as two characters.
(Such as the last Chinese character to take more, do not take less, then do not take, that is, the actual number of characters to take num-1.
If the first character of the string is Chinese and num = 1, an empty string is returned.
Function strleft (STR, num)
Dim p_str, p_num
P_str = ""
P_num = 0' defines the variable, which indicates the actual number of characters when the Chinese character is 2 bytes.
If trim (STR) <> "then
For I = 1 to num
If ASC (mid (STR, I, 1)> 255 or ASC (mid (STR, I, 1) <0 then' determines the number of bytes for the next character
P_num = p_num + 2
Else
P_num = p_num + 1
End if
If p_num> num then exit
Next
P_str = left (STR, I-1) 'replaces the I-1 with I, resulting in the opposite situation as in the description.
End if
Strleft = p_str
End Function
'------------------ ******* End ******--------------------
Instance:
<%
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
Next
P_str = left (STR, I-1)
End if
Strleft = p_str
End Function
A = "Love late cnblogs Hongfeng"
B = strleft (A, n)
%>
<% = B %>
When N is 3, the result is "love ";
When the N value is 7, the result is "Love late CNB ";
When the N value is 11, the result is "Love late cnblogs ";
When the N value is 14, the result is "Love late cnblogs red ".
========================
'---------------------------------------------------
' Code Filter
'---------------------------------------------------
'Form 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 form
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 code Filtering
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