Results 1 to 3 of 3

Thread: [RESOLVED] replacing characters in textbox (including special characters)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Location
    Glogow, Poland
    Posts
    104

    Resolved [RESOLVED] replacing characters in textbox (including special characters)

    Hi,

    Please help me a little bit as I'm stuck.

    I have two textboxes. I type in one of them and the text gets copied in real time into another textbox. There is one catch. I need to replace specific character with something else.

    If I enter a quote " in textbox1, it has to be replaced with \" in textbox2.

    I started with something like the below code, but obviously this does not work (tried different stuff - this is for demonstration only). In the example below 'a' represents " , and 'b' represents \"

    Code:
    Private Sub TextBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.KeyUp
    
            TextBox2.Text = TextBox1.Text
    
            If TextBox2.Text.Contains("a") Then
                TextBox2.Text.Replace("a", "b")
            End If
    
    End Sub
    In other words... whenever I enter the quote character into the textbox1 I want it to be replaced in textbox2 with a backslash+quote.

    Example of my goal:

    text in textbox1: Where "Glogow" is?
    text in textbox2: Where \"Glogow\" is?


    Can this be done ?
    Last edited by marl; Aug 5th, 2011 at 03:18 PM. Reason: added an example to make the question clearer

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: replacing characters in textbox (including special characters)

    try this:

    vb Code:
    1. TextBox2.Text = TextBox2.Text.Replace("""", "\""")

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Location
    Glogow, Poland
    Posts
    104

    Thumbs up Re: replacing characters in textbox (including special characters)

    Thanks a lot .paul.

    I cannot believe this is so simple

    issue resolved

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width