蛙蛙推荐:用VBS写了一个字符串实用函数的类

来源:互联网 发布:防止xss攻击php 编辑:程序博客网 时间:2024/05/18 20:46

<!-- 蛙蛙推荐:用VBS写了一个字符串实用函数的类,不知道实用不实用 -->
<%
Class wawa_str                                                         '创建一个名为wawa的类
'*********************************************************
' 目的:字符串实用函数,每个方法做了相应的注释,我没有用正则表达式来判断要
'    搜索字符串的边界,只是简单了写了一下函数,如果要判断边界的话要用/b,
'    主要是vbs的政则表达式不好用,所以就没写,下次有时间再把这个类完善一下
'    并把它改写成C#版本的
' 作者:天极.蛙蛙王子
' 变量:WawaValue(私有变量)
' 属性:   
' 方法:
'*********************************************************
private WawaValue                                              '创建一个内部私有变量
 
 Private Sub Class_Initialize()                                 '定义类的初始化事件
  
  
 End Sub
 Private Sub Class_Terminate   ' 设置 Terminate 事件。           '定义类的清空事件
  
    End Sub
  
 Public Property Let propertywawa(ByVal wawa_arg)               '定义类的一个let属性
  WawaValue=wawa_arg
 End Property
 Public Property Get propertywawa()                             '定义一个类的get属性
  propertywawa=WawaValue
 End Property
 
 Public Function GetFront(ByVal mainStr,ByVal searchStr )                   '获取要搜索字符串左边的字符
  dim FoundOffset
  FoundOffset=instr(mainStr,searchStr)
  If FoundOffset=1 Then
   getfront= ""
  End If
  
  getfront= mid(mainStr,1,foundoffset-1)
 End Function
 
 Public Function getend(ByVal mainStr,ByVal searchStr )                   '获取要搜索字符串右边的字符
  dim FoundOffset
  FoundOffset=instr(mainStr,searchStr)
  If FoundOffset=1 Then
   getend= null
  End If
  getend=mid(mainstr,len(searchstr)+1)
 End Function
 
 Public Function insertString(ByVal mainStr,ByVal searchStr,ByVal insertStr  )         '在要搜索的字符串前插入一个字符串
  dim front,endwawa
  front=getfront(mainstr,searchstr)
  endwawa=getend(mainstr,searchstr)
  insertstring=(front&insertstr&endwawa)
 End Function

 Public Function deleteString(ByVal mainStr,ByVal deletestr)                       '删除要搜索的字符串
  deletestring=replace(mainstr,deletestr,"")
 End Function

 Public Function replaceString(ByVal mainStr,ByVal searchstr,ByVal replacestr)  '替换要搜索的字符串
  dim front,endwawa
  front=getfront(mainstr,searchstr)
  endwawa=getend(mainstr,searchstr)
  replacestring=(front&replacestr&endwawa)   
 End Function
 
End Class
set temp=new wawa_str
response.write(temp.getfront("hellowawa","wawa"))
response.write("<br>")
response.write(temp.getend("wawabyebye","wawa"))
response.write("<br>")
response.write(temp.insertstring("tianwawa","wawa","cai"))
response.write("<br>")
response.write(temp.deletestring("wawatiancai","wawa"))
response.write("<br>")
response.write(temp.replacestring("wawatiancai","wawa","hello"))
response.write("<br>")
'response.write("<br>")
%>