完美字符串截取

来源:互联网 发布:js身份证号码验证规则 编辑:程序博客网 时间:2024/05/08 03:18
<%
Function CountLength(Str)
    
Dim output,ThisChar,i
    output 
= 0
    
For i = 1 To Len(Str)
        ThisChar 
= Mid(Str,i,1)
        
If Asc(ThisChar) < 0 Then
            output 
= output + 2
        
Else
            output 
= output + 1
        
End If
    
Next
    CountLength 
= output
End Function

Function MaxLengthStr(ByVal Str, ByVal MaxLength)
    
Dim Output,i
    
If IsNull(Str) Then Str = ""
    Output 
= ""
    
If LenB(Str) <= MaxLength Then
        Output 
= Str
    
Else
        
For i = 1 To Len(Str)
            Output 
= Output & Mid(Str,i,1)
            
If CountLength(Output)+3 = MaxLength Then
                Output 
= Output & "..."
                
Exit For
            
ElseIf CountLength(Output)+3 > MaxLength Then
                Output 
= Left(Output,Len(Output)-1& "..."
                
Exit For
            
End If
        
Next
    
End If
    MaxLengthStr 
= Output
End Function

Response.Write MaxLengthStr(
"Osdne Wor21421阿瑟大ld One Dream,北京"40)
response.write 
"<br>"
Response.Write MaxLengthStr(
"北京2008,Onsf234eWorld One Dream,北京2008"41)



Function Strlength(Str)
    Temp_Str
=Len(Str)
    
For I=1 To Temp_Str
        Test_Str
=(Mid(Str,I,1))
        
If Asc(Test_Str)>0 Then
            Strlength
=Strlength+1
        
Else
            Strlength
=Strlength+2
        
End If
    
Next
End Function

Function Strleft(Str,L)
    Temp_Str
=Len(Str)
    
For I=1 To Temp_Str
        Test_Str
=(Mid(Str,I,1))
        Strleft
=Strleft&Test_Str
        
If Asc(Test_Str)>0 Then
            lens
=lens+1
        
Else
            lens
=lens+2
        
End If
        
If lens>=Then Exit For
    
Next
End Function

Response.Write Strleft(
"北008",3)
%
>
 
原创粉丝点击