用數組移動字符串
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