关于VB中的replace函数

来源:百度知道 编辑:UC知道 时间:2024/09/22 23:21:02
如何反复用replace替换啊?比如说

Text1填入abc,点Command1,则在Text2中显示123
Text1填入acb,点Command1,则在Text2中显示132
Text1填入bac,点Command1,则在Text2中显示213

等于是在替换单独的字符,不是整体……也就是说……不要Text1.Text = Replace(Text2.Text, "abc", "123")这样的。

Text2.Text = Replace(Text1.Text, "a", "1")
Text2.Text = Replace(Text1.Text, "b", "2")
Text2.Text = Replace(text1.Text, "c", "3")
这样好像也不行……

请高手指教,谢谢!

建一个中间变量就可以了。
=================
Private Sub Command1_Click()
Dim t As String
t = Text1.Text
t = Replace(t, "a", "1")
t = Replace(t, "b", "2")
t = Replace(t, "c", "3")
Text2.Text = t
End Sub

不需要用replace啊
dim a as string,b as string,i as integer
for i=1 to len(text1.text) step 1
a=mid(text1.text,i,1)
select case a
case "a"
a=1
case "b"
a=2
case "c"
a=3
end select
b=b & a
next i
text2.text=b