日期:2014-05-17  浏览次数:20950 次

asp如何用随机数替换同一个文本中的同一个字符?
不太好描述。比如有这样的一个字符串:vstr= "...*...*...*... "

我想用不同的字符串来替换其中的“*”,比如替换成: "...ae...dd...esw...we... "

请教用asp该如何实现??谢谢。

------解决方案--------------------
要处理的字符串expression
要替换掉字符串find
用来替换字符串的最大长度MaxLenReplace
str=VReplace(vstr, "* ",3)


Private Function VReplace(expression, find, MaxLenReplace)
Dim A
Dim str, i
A = Split(expression, find)
For i = 0 To UBound(A) - 1
str = str & A(i) & GetStrRnd(CInt(MaxLenReplace * Rnd()))
Next
str = str & A(UBound(A))
VReplace = str
End Function
Private Function GetStrRnd(intLen)
Dim i
Dim str
Randomize
For i = 0 To intLen
str = str & Chr(97 + Rnd() * 26)
Next
GetStrRnd = str
End Function