asp 字符串截取函数

asp 字符串截取函数

'*********************************************************

'函数:cutStr[str(strlen)]

'参数:str,待处理的字符串,strlen,截取的长度

'作者:木木

'日期:2007/7/12

'描述:截取指定长度的字符串

'示例:<%=cutStr("欢迎光临阿里西西",5)%>

'*********************************************************

function cutStr(str,strlen)

 If str = "" Then

 cutStr = "cutStr函数异常:字符串为空"

 exit function

 End If

'------------来源长度检查

 If  strlen = "" Then

 cutStr = "cutStr函数异常:长度未指定"

 exit function

 End If

If  CInt(strlen) = 0 Then

 cutStr = "cutStr函数异常:长度为0"

 exit function

 End If 

'----------检测来源字符长度

 dim l,t,c,i

 l=len(str)

 t=0

'----------循环截取字符

 for i=1 to l

 c=Abs(Asc(Mid(str,i,1)))

 '------判断是否汉字

 if c>255 then

 t=t+2

 else

 t=t+1

 end If

 '------判断是否到达指定长度

 if t>=strlen then

 cutStr=left(str,i)&".."

 exit for

 else

 cutStr=str

 end if

 next

 cutStr=replace(cutStr,chr(10),"")

end function

''*********************************************************

'函数:strlen[str]

'参数:str,待处理的字符串

'作者:木木

'日期:2007/7/12

'描述:判断字符串长度,汉字长度为2

'示例:<%=strlen("欢迎光临阿里西西")%>

'*********************************************************

Function strlen(str)

dim p_len

p_len=0

strlen=0

if trim(str)<>"" then

p_len=len(trim(str))

for xx=1 to p_len

if asc(mid(str,xx,1))<0 then

strlen=int(strlen) + 2

else

strlen=int(strlen) + 1

end if

next

end if

End Function

截取左边的n个字符'*********************************************************

'函数:LeftTrue(str,n)

'参数:str,待处理的字符串,n,截取的长度

'作者:木木

'日期:2007/7/12

'描述:显示左边的n个字符(自动识别汉字)函数

'示例:<%=LeftTrue("欢迎光临阿里西西",6)%>

'*********************************************************

Function LeftTrue(str,n)

If len(str)<=n/2 Then

 LeftTrue=str

Else

 Dim TStr

 Dim l,t,c

 Dim i

 l=len(str)

 t=l

 TStr=""

 t=0

 for i=1 to l

  c=asc(mid(str,i,1))

  If c<0 then c=c+65536

  If c>255 then

  t=t+2

  Else

  t=t+1

  End If

  If t>n Then exit for

  TStr=TStr&(mid(str,i,1))

 next

 LeftTrue = TStr

End If

End Function

时间: 2024-07-29 20:19:38

asp 字符串截取函数的相关文章

asp字符串截取函数

            本文章提供这款asp字符串截取函数原是是先用定义字符串判别函数判断字符串长度以及中英文,再把字符截取后定义超出部分内容的...显示方式            function strvalue(str,lennum)            dim p_num            dim i            if strlen(str)<=lennum then            strvalue=str            else            p

asp 字符串截取函数_应用技巧

asp 字符串截取函数'********************************************************* '函数:cutStr[str(strlen)] '参数:str,待处理的字符串,strlen,截取的长度 '作者:木木 '日期:2007/7/12 '描述:截取指定长度的字符串 '示例:<%=cutStr("欢迎光临阿里西西",5)%> '*************************************************

ASP字符串截取函数,适用于采集程序调用

'********************************************************************************'    Function(公有)'    名称 :   字符串截取函数'    作用 :    按指定首尾字符串截取内容(本函数为从左向右截取)'    参数 :    sContent ---- 被截取的内容'        sStart ------ 首字符串'        iStartNo ---- 当首字符串不是唯一时取第几

asp小偷程序中的字符串截取函数

函数|字符串|小偷程序 asp小偷程序中的字符串截取函数 以下是函数代码:'******************************************************************************** '    Function(公有) '    名称 :    字符串截取函数 '    作用 :    按指定首尾字符串截取内容(本函数为从左向右截取) '    参数 :    sContent ---- 被截取的内容 '        sStart ----

asp.net字符串截取函数

asp教程.net字符串截取函数 本教程先是告诉你用最简单的方法取对字符串进行截取,再后面写了一个实用的程序来对数据进行字符串截取哦. */ //c# string mystring = "abc"; bool test1 = mystring.substring(2, 1).equals("c"); // this is true. //vb substring microsoft.visualbasic.left(string, length)  //一个简单智

php使用字符串截取函数从结尾删除字符串

修复了一个获取控制器名称方法的bug 控制器的名称都是使用act结尾,使用过程中要删除act. 1.原来的方法 //使用替换act的方法获取控制器名称,很显然当控制器的名称出现act三个字符的时候都会被替换掉产生bug $actName = str_replace( 'act', '', 'ad_client_contactact'); 控制器名称 ad_client_cont 2.修复后的方法 //从结尾删除三个字符串 $actName = substr('ad_client_contacta

asp字符截取函数

asp字符截取函数,取字符函数 <% '定义字符串判别函数 function strlen(str) dim p_len p_len=0 strlen=0 if trim(str)<>"" then p_len=len(trim(str)) for xx=1 to p_len if asc(mid(str,xx,1))<0 then strlen=int(strlen) + 2 else strlen=int(strlen) + 1 end if next en

JS字符串截取函数实例

 这篇文章主要介绍了JS字符串截取函数实例,有需要的朋友可以参考一下 使用 substring()或者slice()     函数:split()  功能:使用一个指定的分隔符把一个字符串分割存储到数组 例子: 代码如下: str="jpg|bmp|gif|ico|png"; arr=theString.split("|"); //arr是一个包含字符值"jpg"."bmp"."gif"."ico

php自定义中文字符串截取函数substr_for_gb2312及substr_for_utf8示例_php技巧

本文实例讲述了php自定义中文字符串截取函数substr_for_gb2312及substr_for_utf8用法.分享给大家供大家参考,具体如下: /* *gb2312中文字符串截取 */ function substr_for_gb2312($str,$start,$len=null) { $totlelength = strlen($str); //特例情况 if ($len == null) $len = $totlelength; if ($len ==0) return ""