首页 > 开发 > 综合 > 正文

用数组移动字符串

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
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表