A string-processing class-enhanced version of ASP (VBScript)

Source: Internet
Author: User
Tags filter bool check character chr comparison strlen trim
Related articles See:

http://www.csdn.net/Develop/read_article.asp?id=22695

This article on the basis of a number of additions, add a few suitable for Chinese web site function to go in, there may be some did not add, there are interested friends can then add a little function on this basis, but don't forget to share!

<%
Class Stringoperations

'***********************************************************************
' @ Feature Description: Swap string for char-type array
' @ parameter Description:-str [string]: a string to convert
' @ return value:-[array] char array
'************************************************************************
Public Function ToCharArray (ByVal str)
ReDim Chararray (Len (str))
For i = 1 to Len (str)
Chararray (i-1) = Mid (str,i,1)
Next
ToCharArray = Chararray
End Function

'****************************************************************************
' @ Function Description: Converts an array into a string
' @ parameter Description:-arr [Array]: data that needs to be converted
' @ return Value:-[string] string
'****************************************************************************
Public Function arraytostring (ByVal arr)
For i = 0 to UBound (arr)
Strobj = strobj & Arr (i)
Next
varraytostring = Strobj
End Function

'****************************************************************************
' @ Feature Description: Check source string str starts with chars
' @ parameter Description:-str [string]: source string
' @ parameter Description:-chars [string]: Character/string of comparison
' @ return value:-[bool]
'****************************************************************************
Public function StartsWith (ByVal str, chars)
If left (Str,len (chars)) = Chars Then
StartsWith = True
Else
StartsWith = False
End If
End Function

'****************************************************************************
' @ Feature Description: Check source string str to end with chars
' @ parameter Description:-str [string]: source string
' @ parameter Description:-chars [string]: Character/string of comparison
' @ return value:-[bool]
'****************************************************************************
Public Function EndsWith (ByVal str, chars)
If Right (Str,len (chars)) = Chars Then
EndsWith = True
Else
EndsWith = False
End If
End Function

'****************************************************************************
' @ Feature Description: Copy n string str
' @ parameter Description:-str [string]: source string
' @ parameter Description:-n [int]: number of copies
"@ return Value:-[string] copied string
'****************************************************************************


Public Function Clone (ByVal str, n)
For i = 1 to n
Value = value & str
Next
Clone = value
End Function

'****************************************************************************
' @ Feature Description: Delete source string The first n characters of str
' @ parameter Description:-str [string]: source string
' @ parameter Description:-n [int]: number of characters deleted
"@ return Value:-[string] deleted string
'****************************************************************************
Public function TrimStart (ByVal str, n)
Value = Mid (str, n+1)
TrimStart = value
End Function

'****************************************************************************
' @ Feature Description: Deletes the last n string of the source string str
' @ parameter Description:-str [string]: source string
' @ parameter Description:-n [int]: number of characters deleted
"@ return Value:-[string] deleted string
'****************************************************************************
Public function trimend (ByVal str, n)
Value = Left (str, Len (str)-N)
TrimEnd = value
End Function

'****************************************************************************
' @ Feature Description: Check character character is English character A-Z or a-Z
' @ parameter Description:-character [char]: Character checked
' @ return value:-[bool] If it is an English character, returns true, False instead
'****************************************************************************
Public Function isalphabetic (byVal character)
Asciivalue = CInt (ASC (character))
if (<= asciivalue and Asciivalue <=) or (<= Asciivalue and Asciivalue <=) 122
Isalphabetic = True
Else
Isalphabetic = False
End If
End Function

'****************************************************************************
' @ Feature Description: Case conversion of STR string
' @ parameter Description:-str [string]: source string
' @ return Value:-[string] converted String
'****************************************************************************
Public function swapcase (str)
For i = 1 to Len (str)
Current = Mid (str, I, 1)
If Isalphabetic (current) Then
High = ASC (UCase)
Low = ASC (LCase (current))
sum = high + low
return = return & Chr (SUM-ASC)
Else
return = return & current
End If
Next
Swapcase = return
End Function

'****************************************************************************
' @ Feature Description: Converts the first letter of each word in the source string str to uppercase
' @ parameter Description:-str [string]: source string
' @ return Value:-[string] converted String
'****************************************************************************
Public function capitalize (str)
Words = Split (str, "")
For i = 0 To UBound (words)
If not i = 0 Then
TMP = ""
End If
TMP = tmp & UCase (left (words (i), 1)) & Right (words (i), Len (words (i))-1)
Words (i) = tmp
Next
Capitalize = arraytostring (words)
End Function

'****************************************************************************
' @ Feature Description: ' Filter the source character ' after Str '
' @ parameter Description:-str [string]: source string
' @ return Value:-[string] converted String
'****************************************************************************
Public Function Checkstr (STR)
If Trim (str) = "" Or IsNull (str) Then
Checkstr= ""
Else
Checkstr=replace (Trim (STR), "'", "" ")
End If
End Function


****************************************************************************
' @ Feature Description: Filter the HTML code in str in the string
' @ parameter Description:-str [string]: source string
' @ return Value:-[string] converted String
'****************************************************************************
Public Function HtmlEncode (str)
If Trim (str) = "" Or IsNull (str) Then
Htmlencode= ""
Else
Str=replace (str, ">", ">")
Str=replace (str, "<", "<")
Str=replace (STR,CHR (32), "")
Str=replace (STR,CHR (9), "")
Str=replace (STR,CHR (34), "" ")
Str=replace (STR,CHR (39), "'")
Str=replace (STR,CHR (13), "")
Str=replace (STR,CHR) & Chr (a), "</p><p>"
Str=replace (STR,CHR), "<br>"
Htmlencode=str
End If
End Function

    ' ****************************************************************************
     ' @ Feature Description: Calculates the length of the source string str (one Chinese character is 2 bytes long)
    ' @ parameter description: -str [string]: source string
 & nbsp;  ' @ return value:  -[Int] source string length
    ' ********************************************
 public Function strLen (str)
  If Trim (str) = "" Or IsNull (str) Then
   strlen=0
  Else
   Dim p_len,x
   p_len=0
   strlen= 0
   P_len=len (Trim (STR))
   for x=1 to P_len
    If Asc (Mid (str,x,1)) <0 Then
     strlen=int (StrLen) + 2
    Else
      Strlen=int (StrLen) + 1
    End If
   Next
  End If
 end function< /p>

'****************************************************************************
' @ Feature Description: Intercept source string Str's front lennum characters (one Chinese character is 2 bytes long)
' @ parameter Description:-str [string]: source string
' @ parameter Description:-lennum [int]: Length of intercept
' @ return Value:-[string]: converted String
'****************************************************************************
Public Function cutstr (str,lennum)
Dim P_num
Dim i,x
If StrLen (Str) <=lennum Then
Cutstr=str
Else
P_num=0
X=0
Do, not p_num > LenNum-2
X=x+1
If ASC (Mid (str,x,1)) <0 Then
P_num=int (P_num) + 2
Else
P_num=int (p_num) + 1
End If
Cutstr=left (Trim (STR), X) & "..."
Loop
End If
End Function

End Class
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.