新手请教一个asp循环替换问题

来源:百度知道 编辑:UC知道 时间:2024/05/23 15:08:06
<%
textarea = "A你B我"
dim BFchar(10),LTchar(10)
BFchar(0) = "A"
BFchar(1) = "B"
BFchar(2) = "C"
BFchar(3) = "D"
BFchar(4) = "E"
BFchar(5) = "F"
BFchar(6) = "G"

LTchar(0) = "a"
LTchar(1) = "b"
LTchar(2) = "c"
LTchar(3) = "d"
LTchar(4) = "e"
LTchar(5) = "f"
LTchar(6) = "g"

for i = 0 to ubound(BFchar)
if instr(textarea,BFchar(i)) > 0 then
textarea = replace(textarea,BFchar(i),LTchar(i))
response.write textarea
end if
Next
response.End
%>
textarea = "A你B我" 经上面代码替换后得到的结果是:
"a你B我a你b我a你b我a你b我a你b我a你b我"
而我只要得到"a你b我"就可以了。应如何修改???

你这个循环了六次,肯定有六串值哈,稍微改一下,给你分析一下哈!
for i = 0 to ubound(BFchar)
if instr(textarea,BFchar(i)) > 0 then
textarea = replace(textarea,BFchar(i),LTchar(i))
response.write textarea
end if
Next
response.End

改成
for i = 0 to ubound(BFchar)
if instr(textarea,BFchar(i)) > 0 then
textarea = replace(textarea,BFchar(i),LTchar(i))
end if
Next
response.write textarea
response.End
就行了,记得最后的输出结果不要放到循环里边去,要么就出怪结果了~~

我汗!我不懂 路过我也正在学