如果单个字符与VB中的另一个字符匹配,则将其替换为字符串中的随机字符

问题描述 投票:0回答:1

我想要一种超级简单的方法,用一个随机字符替换字符串中的另一个字符。到目前为止,对于如此简单的事情,我发现非常复杂。

vb.net
1个回答
0
投票
Dim result As String
For Each character As String In FormatTextBox.Text
    If character = "c" Then
       result += GetRandomLetter(97, 123)
    ElseIf character = "C" Then
       result += GetRandomLetter(65, 91)
    Else
       result += character
    End If
 Next

Public Function GetRandomLetter(AsciStart As Integer, AsciEnd As Integer) As Char
    Dim TheIndex As Integer = RandomNumber.Next(AsciStart, AsciEnd)
    Return Chr(TheIndex)
End Function
© www.soinside.com 2019 - 2024. All rights reserved.