也有注意的地方,如果用在循环中,因不变量“i”也是常用于循环的变量,执行以下函数时,“i”的值会发生变化,如果是调用他的循环中用到相同的变量,会产生未知的结果,请换用其它变量名。
以下用法和len(),left(),right()一样。
程序代码
复制代码 代码如下:
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
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!