Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Need help with VB.NET(Difficulty:Easy)?

i'm supposed to replace each character in textbox1 to special characters assigned. But in this code the actual text gets replaced, I don't want that to happen,instead I want that to be shown in textbox2 retaining actual text in textbox1. How can I do that?

Here is the code:

Private arLetterChars() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 "

Private arEncryptedChars() As Char = "¿ɸ¢ç¶‹!˜Ö´åÄÚᴁÍìæ¯~[Ûÿ|ÑûÏÉí³èô§ŠÀÙ:ÒÓ?>þ.äƒ%*š¾†±♠}@æŒ#/{۞],"

'// encrypt.

Private Sub Btnaddenc_Click(sender As System.Object, e As System.EventArgs) Handles BtnAddEnc.Click

With Textbox1

For Each myTextBoxChar As Char In Textbox1.Text '// loop thru TextBox, one char. at a time.

For i As Integer = 0 To arLetterChars.Length - 1 '// loop thru all letters in the Array.

'// if TextBox char ='s the char in your Array, replace the TextBox char with the same #'ed Array char of the Encrypted letters.

If myTextBoxChar = arLetterChars(i) Then Textbox1.Text = Textbox1.Text.Replace(myTextBoxChar, arEncryptedChars(i))

Next

Next

End With

End Sub

I tried to replace Textbox1.Text = Textbox1.Text.Replace(myTextBoxChar, arEncryptedChars(i)) to Textbox2.Text = Textbox1.Text.Replace(myTextBoxChar, arEncryptedChars(i)).

But that did not replace all characters to special character.

eg: Mathew should be ?É*Àô† but it is mathe†

1 Answer

Relevance
  • 7 years ago
    Favorite Answer

    I changed your code a little and added a Dictionary type variable to hold the 'encryption'. The encryption answer is stored in encString.

    Private arLetterChars() As Char = "ABCDEFGH" 'etc

    Private arEncryptedChars() As Char = "¿ɸ¢ç¶‹!˜" 'etc

    Private Sub Btnaddenc_Click(sender As System.Object, e As System.EventArgs) Handles Btnaddenc.Click

    Dim encDict As New Dictionary(Of String, String)

    Dim encString As String = ""

    For p as Integer = 0 To arLetterChars.Length - 1

    encDict.Add(arLetterChars(p), arEncryptedChars(p))

    Next

    For Each c As Char In TextBox1.Text

    encString += encDict(c)

    Next

    TextBox2.Text = encString

    End Sub

Still have questions? Get your answers by asking now.