Farooque Ali

Farooque Ali

  • NA
  • 254
  • 239.8k

String Replace

Jun 6 2012 8:33 AM

Hi,Below is my program to replace the string A to Z, B to Y .. . ..... Z to A and so on

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim sample As String
sample = TextBox1.Text
Dim letter As String = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
Dim letter1 As String = "ZzYyXxWwVvUuTtSsRrQqPpOoNnMmLlKkJjIiHhGgFfEeDdCcBbAa"        
For Each s As String In sample
Dim i As Integer            
For i = 0 To letter.Length - 1                
If s = letter(i) Then                    
TextBox2.Text += letter1(i)                
End If            
Next
Next 

End Sub

Here i want the program, that should have only one for loop and inside the loop should not use the if conditions. Need the optimized code. Can anyone help me please


 


Answers (3)