vb.net正则表达式替换多个字符

时间:2014-12-12 12:42:55

标签: regex vb.net

是否可以通过仅使用输入字符串,搜索模式和替换模式将多个字符替换为相应的映射(o - > 0,Z - > 7,B = 8)?

1 个答案:

答案 0 :(得分:1)

使用Dictionary(Of String, String)并循环String.Replace

Dim replacementMapper As New Dictionary(Of String, String)
replacementMapper.Add("o", "0")
replacementMapper.Add("T", "7")
replacementMapper.Add("B", "8")
Dim inputString = "This is just an example which is completely pointless."
For Each kv In replacementMapper
    inputString = inputString.Replace(kv.Key, kv.Value)
Next