vb.net 在VB中替换单个字符串中的多个字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31906035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Replacing multiple characters from a single string in VB
提问by Anonymous
Is it possible to replace multiple characters from a string in Visual Basic, like for example:
是否可以在 Visual Basic 中替换字符串中的多个字符,例如:
mary had a little lamb
All letter amust be changed to z,
all mmust be changed to y,
all tmust be changed to xin just one line of code?
所有字母都a必须改成z,都m必须改成y,都t必须改成x一行代码?
回答by Andrew Morton
As the result of Replaceis a string, you can concatenate multiple replacements:
由于结果Replace是一个字符串,您可以连接多个替换:
Dim s As String = "mary had a little lamb"
Dim t As String = s.Replace("a", "z").Replace("m", "y").Replace("t", "x")
Console.WriteLine(t) ' outputs "yzry hzd z lixxle lzyb"

