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

VulpesPosted Jun 6, 2012, 10:35 AM
Farooque AliPosted Jun 6, 2012, 9:13 AM
Thanks for your reply, But here one more thing need to be discussed, The string which is declared as letter and letter1 should not use that also,
Is any other way there to create program without using that declaration.
VulpesPosted Jun 6, 2012, 9:00 AM
However, if there are other characters, you'll get an exception and the only way to prevent that is to use an 'If' statement within the For Each loop.
Notice that it's best to build up the translated string within a temporary variable and then assign it to TextBox2.Text so you only have to alter the UI once: