elva

个人扩展的asp字符串函数

<%
'' @参数说明: - str [string]: 源字符串
'' @参数说明: - chars [string]: 比较的字符/字符串
'' @返回值: - [bool]
'****************************************************************************
public function endsWith(byVal str, chars)
if Right(str,len(chars)) = chars then
endsWith = true
else
endsWith = false
end if
end function

'****************************************************************************
'' @功能说明: 复制N个字符串str
'' @参数说明: - str [string]: 源字符串
'' @参数说明: - n [int]: 复制次数
'' @返回值: - [string] 复制后的字符串
'****************************************************************************
public function clone(byVal str, n)
for i = 1 to n
value = value & str
next
clone = value
end function

'****************************************************************************
'' @功能说明: 删除源字符串str的前N个字符
'' @参数说明: - str [string]: 源字符串
'' @参数说明: - n [int]: 删除的字符个数
'' @返回值: - [string] 删除后的字符串
'****************************************************************************
public function trimStart(byVal str, n)
value = Mid(str, n+1)
trimStart = value
end function

'****************************************************************************
'' @功能说明: 删除源字符串str的最后N个字符串
'' @参数说明: - str [string]: 源字符串
'' @参数说明: - n [int]: 删除的字符个数
'' @返回值: - [string] 删除后的字符串
'****************************************************************************
public function trimEnd(byVal str, n)
value = Left(str, len(str)-n)
trimEnd = value
end function

'****************************************************************************
'' @功能说明: 检查字符character是否是英文字符 A-Z or a-z
'' @参数说明: - character [char]: 检查的字符
'' @返回值: - [bool] 如果是英文字符,返回TRUE,反之为FALSE
'****************************************************************************
public function isAlphabetic(byVal character)
asciiValue = cint(asc(character))
if (65 <= asciiValue and asciiValue <= 90) or (97 <= asciiValue and asciiValue <= 122) then
isAlphabetic = true
else
isAlphabetic = false
end if
end function

'****************************************************************************
'' @功能说明: 对str字符串进行大小写转换
'' @参数说明: - str [string]: 源字符串
'' @返回值: - [string] 转换后的字符串
'****************************************************************************
public function swapCase(str)
for i = 1 to len(str)
current = mid(str, i, 1)
if isAlphabetic(current) then
high = asc(ucase(current))
low = asc(lcase(current))
sum = high + low
return = return & chr(sum-asc(current))
else
return = return & current
end if
next
swapCase = return
end function

'****************************************************************************
'' @功能说明: 将源字符串str中每个单词的第一个字母转换成大写
'' @参数说明: - str [string]: 源字符串
'' @返回值: - [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

'end class
'****************************************************************************
public Function Strlen(txt)
    txt=trim(txt)
    x = len(txt)
    y = 0
    for ii = 1 to x
        if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then
            y = y + 2
        else
            y = y + 1
        end if
    next
    Strlen = y

End Function


'****************************************************************************
'判断中英文结合的字段串长度的小函数
'****************************************************************************
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>=L Then Exit For
Next
End Function

Function Strright(Str,L)
Temp_Str=Len(Str)
For i = Temp_Str to 1 step -1
Test_Str=(Mid(Str,I,1))
Strright=Test_Str&Strright
If Asc(Test_Str)>0 Then
lens=lens+1
Else
lens=lens+2
End If
If lens>=L Then Exit For
Next
End Function
'****************************************************************************
'len(),lift(),right()不能正常识别中文的解决方法
'****************************************************************************

 


'****************************************************************************
'****************************************************************************
'****************************Write by elva***********************************
'****************************************************************************
'****************************************************************************
public function getstr(byVal str, x,y)
 value = Left(str,x)
 value = Right(value,y)
 getstr = Ltrimch(value,0)
 'getstr = Rtrimch(value,0)
end function
'****************************************************************************
'' @功能说明: 取得字符串中的某字符串作为新串.x是到此字符串的长度,y是该字符串长度
''@返回值,新的字符串
'****************************************************************************
public function Ltrimch(byVal str,c)
 value = str
 while (InStr(value,c) = 1)
  value = Mid(value, 2)
 wend
 Ltrimch = value
end function
'****************************************************************************
'' @功能说明: 去掉字符串前面填充的 0
''@注:从左面截取。
'****************************************************************************
public function Rtrimch(byVal str,c)
 value = str
 'while (Right(value,1) = c)
 while (StrComp(Right(value,1),c) = 0 )
  value = Left(value,len(value)-1)
  'response.write value & "||" & Right(value,1) & "||"& "ok<br>"
 wend
 response.write Right(value,1) & "<br>"
 Rtrimch = value
end function
'****************************************************************************
'' @功能说明: 去掉字符串前面填充的 0
''@注:从右面截取。
'****************************************************************************
%>

posted on 2007-05-28 23:39 叶子 阅读(425) 评论(0)  编辑 收藏 引用 所属分类: ASP


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理