Question Replace a letter in a textbox with another letter

Muchni

Member
Joined
Sep 30, 2008
Messages
18
Programming Experience
1-3
Im making a program in vb.net 2008. You can open txt files and type in a textbox (so far like microsoft word, almost). But the thing is you can save in a diefferent fileending (my own) and I want to cryptonize it, ( not sure thats how you say in english but hope u get it) Like if you type in just an
"a"
then it changes in the saving file like
"x1"
what I wrote was

Code:
 If sve.Text.Contains(a1) Then 'sve is a textbox
            Replace(sve.Text, a1, "x1") '  Dim a1 As String = "a"

        End If
But when it saves it saves like i wrote "a" not "x1"
here is the whole code in the saving sub
Code:
 Private Sub SaveFileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveFileToolStripMenuItem.Click
        SaveFileDialog1.Filter = "Textfiler (*.txt)|*.txt|Informationsfiler (*.nfo)|*.nfo|Brynäs (*.bif)|*.bif|Alla filer (*.*)|*.*"
        Dim convert As String
        Dim a1 As String = "a", b1 As String = "b", c1 As String = "c", d1 As String = "d", e1 As String = "e", f1 As String = "f", g1 As String = "g", h1 As String = "h", i1 As String = "i", j1 As String = "j", k1 As String = "k", l1 As String = "l", m1 As String = "m", n1 As String = "n", o1 As String = "o", p1 As String = "p", q1 As String = "q", r1 As String = "r", s1 As String = "s", t1 As String = "t", u1 As String = "u", v1 As String = "v", w1 As String = "w", x1 As String = "x", y1 As String = "y", z1 As String = "z"
        If sve.Text.Contains(a1) Then
            Replace(sve.Text, a1, "x1")

        End If
        If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim ad As New System.IO.StreamWriter(SaveFileDialog1.FileName)
            ad.Write(sve.Text)
            ad.Close()
            sve.Visible = False
            sve.Text = ""
        Else



        End If





    End Sub
 

demausdauth

Well-known member
Joined
Mar 24, 2008
Messages
281
Location
Minnesota
Programming Experience
3-5
The Replace function returns a string with all the replacements done, so you will need to assign it to a variable before you put into the file.

Code:
sve.Text = "a little test"

Dim finishedstring As String = ""
finishedstring = sve.Text.Replace(a1,"x1"c)
finishedstring will be 'x1 little test' when done, and finishedstring is what you want to write to the file.
 
Top Bottom