将字符串“OAIPOAIPOAPKAPIOAMAPIA中“A”字符替换成数字第一次出现替换成1,第二次出现替换成2以此类推 20
1个回答
展开全部
Sub Main()
Dim input = "OAIPOAIPOAPKAPIOAMAPIA"
Dim output = Replace(input, "A")
Console.WriteLine(output)
Console.ReadLine()
End Sub
Function Replace(ByVal input As String, ByVal a As Char) As String
Dim cnt = 0
Dim sb As New StringBuilder
Dim ch As Char
For Each c In input
If a = c Then
cnt = cnt + 1
ch = cnt.ToString
Else
ch = c
End If
sb.Append(ch)
Next
Return sb.ToString
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询