CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Question Replace doesn't seem to work?

    I have some code a bit like this:

    Dim string1 as string
    string1 = "some text"

    Dim tempstr as string
    tempstr = Replace(string1,"xt","ab")

    string1 = tempstr


    Now I believe string1 should be "some teab", but in fact it is unchanged.
    What can be wrong?
    I must add, that I haven't touched vb for more than 10 years, so I'm feeling my way into the syntax again...

  2. #2
    Join Date
    Jul 2005
    Posts
    1,083

    Re: Replace doesn't seem to work?

    The code works ok
    Code:
    Dim string1 As String
    Dim tempstr As String
        string1 = "some text"
        tempstr = Replace(string1, "xt", "ab")
        string1 = tempstr
        MsgBox string1
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Replace doesn't seem to work?

    Yep what you have shown would work, if that is your actual code then how are you checking string1 to see what the value is? If that is not the actual code then be sure to keep in mind that many string functions are case sensitive by default.
    Always use [code][/code] tags when posting code.

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

Featured