Reputation: 21
Is it possible to replace multiple characters from a string in Visual Basic, like for example:
mary had a little lamb
All letter a
must be changed to z
,
all m
must be changed to y
,
all t
must be changed to x
in just one line of code?
Upvotes: 2
Views: 8914
Reputation: 25066
As the result of Replace
is a string, you can concatenate multiple replacements:
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"
Upvotes: 5