用数组移动字符串
2024-07-21 02:22:48
供稿:网友
,欢迎访问网页设计爱好者web开发。这是2个对字符串处理的互逆函数
功能:移动字符串
用发:arymoveleft("字符串",移动的个数)
例:
dim strg
strg="123456789"
strg=arymoveleft(strg,2)
结果:strg="345678912"
public function arymoveleft(str, count)
if count = 0 then
arymoveleft = str
exit function
end if
dim a()
strlen = len(str)
redim a(strlen)
for i = 1 to len(str)
a(i) = mid(str, i, 1)
next
temp = a(1)
for i = 2 to len(str)
a(i - 1) = a(i)
next
a(strlen) = temp
for i = 1 to len(str)
result = result & a(i)
next
arymoveleft = arymoveleft(result, count - 1)
end function
public function arymoveright(str, count)
if count = 0 then
arymoveright = str
exit function
end if
dim a()
strlen = len(str)
redim a(strlen)
for i = 1 to len(str)
a(i) = mid(str, i, 1)
next
temp = a(strlen)
for i = len(str) to 2 step -1
a(i) = a(i - 1)
next
a(1) = temp
for i = 1 to len(str)
result = result & a(i)
next
arymoveright = arymoveright(result, count - 1)
end function