vb编程编写一个函数,删除一个字符串中的特定字符

2024-12-04 09:07:07
推荐回答(2个)
回答(1):

'定带早岁义一个find函数
Private Function find(s1 As String, s2 As String) As String
Dim i As Integer
For i = 1 To Len(s1)
If i = InStr(1, s1, s2, vbTextCompare) Then
find = Left(s1, i - 1) & Right(s1, Len(s1) - Len(s2) - i + 1)
Exit Function
End If
Next i
find = s1
End Function

'将Text1.Text中的Text2.Text字符删睁巧除蠢睁
Private Sub Command1_Click()
Dim s As String
s = find(Text1.Text, Text2.Text)
Text1.Text = s
End Sub

回答(2):

将要删去雹正的字铅蠢符替换成空即可啊。

Replace("abcabcs", "c", "")

返回值就是"abcabcs"去掉源激悔了字符"c"的结果"ababs"。