user5193861
user5193861

Reputation:

Replacing every letter

The code supposed to replace the letters to image links but it sometimes replace for example: heyho to heoo and thats the problem. Please help me with this guys!

    Imports System.Text.RegularExpressions

    Public Class Form1
        Dim DefURL = "http://www.roblox.com/-------------------------------" & _ 
                     "-----------------------------------------------------" & _
                     "---------------------------"

        Dim myString = ""
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        End Sub
        Sub Delay(ByVal dblsecs As Double)
            Const onesec As Double = 1.0# / (1440.0# * 60.0#)
            Dim dblWaitTil As Date
            Now.AddSeconds(onesec)
            dblWaitTil = Now.AddSeconds(onesec).AddSeconds(dblsecs)
            Do Until Now > dblWaitTil
                Application.DoEvents()

            Loop
        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            myString = ""
            myString = TextBox1.Text.ToLower
            Dim sb As String
            For Each ch As Char In TextBox1.Text
                Dim s As String
                Console.WriteLine(ch)
                Select Case ch
                    Case "a"c : s = "http://www.roblox.com/--item?id=2273128"
                    Case "b"c : s = "http://www.roblox.com/--item?id=2273124"
                    Case "c"c : s = "http://www.roblox.com/--item?id=2273121"
                    Case "d"c : s = "http://www.roblox.com/--item?id=2273119"
                    Case "e"c : s = "http://www.roblox.com/--item?id=2273116"
                    Case "f"c : s = "http://www.roblox.com/--item?id=2273114"
                    Case "g"c : s = "http://www.roblox.com/--item?id=2273111"
                    Case "h"c : s = "http://www.roblox.com/--item?id=2273107"
                    Case "i"c : s = "http://www.roblox.com/--item?id=2273105"
                    Case "j"c : s = "http://www.roblox.com/--item?id=2273102"
                    Case "k"c : s = "http://www.roblox.com/--item?id=2273099"
                    Case "l"c : s = "http://www.roblox.com/--item?id=2273095"
                    Case "m"c : s = "http://www.roblox.com/--item?id=2273093"
                    Case "n"c : s = "http://www.roblox.com/--item?id=2273090"
                    Case "o"c : s = "http://www.roblox.com/--item?id=2273088"
                    Case "p"c : s = "http://www.roblox.com/--item?id=2273086"
                    Case "q"c : s = "http://www.roblox.com/--item?id=2273082"
                    Case "r"c : s = "http://www.roblox.com/--item?id=2273078"
                    Case "s"c : s = "http://www.roblox.com/--item?id=195452703"
                    Case "u"c : s = "http://www.roblox.com/--item?id=2273071"
                    Case "v"c : s = "http://www.roblox.com/--item?id=2273067"
                    Case "w"c : s = "http://www.roblox.com/--item?id=2273065"
                    Case "x"c : s = "http://www.roblox.com/--item?id=2273062"
                    Case "y"c : s = "http://www.roblox.com/--item?id=2273060"
                    Case "t"c : s = "http://www.roblox.com/--item?id=2273073"
                    Case "z"c : s = "http://www.roblox.com/--item?id=2273058"
                    Case " "c : s = "http://www.roblox.com/--item?id=269779634"
                End Select
                sb = sb & s
            Next
            My.Computer.Clipboard.SetText(sb.ToString)
        End Sub
    End Class

(Please ignore this as the editor will not let me submit unless I add more text. I simply wanted to fix the formatting for Umom Mommi so that it meets the formatting standards. - Thanks - Nerd)

Upvotes: 0

Views: 161

Answers (1)

Blackwood
Blackwood

Reputation: 4534

To avoid replacing characters in the string you already inserted, you can loop through all the characters in the original string and build a new string with the replacement text.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim sb As New System.Text.StringBuilder 
    For Each ch As Char In TextBox1.Text
        Dim s As String 
        Select Case ch
            Case "a"c: s = "http://www.roblox.com/--item?id=2273128 "
            Case "b"c: s = "http://www.roblox.com/--item?id=2273124 "
            Case "c"c: s = "http://www.roblox.com/--item?id=2273121 "
            Case Else: s = ch 
        End Select
        sb.Append(s)
    Next
    My.Computer.Clipboard.SetText(sb.ToString)
End Sub

Upvotes: 2

Related Questions