asp截取字符串
   
   
   
    时间:2009-03-25    点击:1727   
    
    
 
    <%
'在Str中截取长度为Length的字符串
Public Function InterceptStr(Str,Length)
	Dim Str1,StrLength,I,Counter
 	'定义标志位Flag,记录是否是中文字符,0代表"否",1代表"是"
	Dim Flag
	Flag=0
	Str1=Trim(Str)
	StrLength = Len(Str)
	Counter = 0
    If Length > 0 Then
		If StrLength >= 1 then
			For I = 1 To StrLength
				If Asc(Mid(Str, I, 1)) < 0  Or Asc(Mid(Str, I, 1)) > 255 Then
					'如果是中文字符
					Flag=1
					Counter = Counter + 2
				Else
					Counter = Counter + 1
				End if
				If Counter >= Length Then
					'如果截取的字符长度未超过原字符串
					If Flag=1 And Counter > Length Then
					'如果是中文字符并且只截取一个字节
					Str1 = Left(Str1, I-1)
				Else
					Str1 = Left(Str1, I)
				End If
				Exit For
                End if
			Next
            InterceptStr = Str1
        Else
            InterceptStr = ""
        End if
	Else
	 	 InterceptStr = ""
	End If
End Function
%>
<form name="form1" method="post" action="">
 <p> 输入字符串和截取长度:</p> 
  <p> 字符串: 
    <input name="text1" type="text" id="text">
  </p>
  <p> 截取长度: 
    <input name="text2" type="text" id="text">
    <input type="submit" name="Submit" value="提交">
  </p>
</form>
<%
Dim X,Y
X=Request.Form("text1")
Y=Request.Form("text2")
If X<>"" and Y<>"" Then
%>
<p>在字符串“<%=X%>”中截取长度为<%=Y%>的字符串:<%=InterceptStr(X,CInt(Y))%></p>
<%
End If
%>
       
  
     	
 asp计算中英文混合字符串的长度
  asp计算中英文混合字符串的长度
	     	
 asp判断字符串是否以指定字符串开头或结尾
  asp判断字符串是否以指定字符串开头或结尾
	     	
 asp判断字符是否是英文字符
  asp判断字符是否是英文字符
	     	
 asp检测字符串出现的次数
  asp检测字符串出现的次数
	     	
 asp过滤字符串中的HTML代码
  asp过滤字符串中的HTML代码
	     
    
    
    
 
             
  
   
  
  
  地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
    
  
  © Copyright 2012 上海网络 
Product  All Rights Reserved