none
Problem of Replace function.

    Question

  •         Dim str

            str = "aaxxbbxxccxx"

            str = Strings.Replace(str, "xx", "WWW", 7, 1)
            MsgBox(str)

     

    The result I expect is : aaxxbbWWWccxx
    But I get result : WWWccxx

     

    How can I get result I expect by Replace function.

    Thanks.

    Friday, April 18, 2008 9:48 AM

Answers

  • That's the expected behavior. The returned string will start at the given starting index.

    The documentation of Strings.Replace says:

    The return value of the Replace function is a string that begins at the position specified by Start and concludes at the end of the Expression string, with the substitutions made as specified by the Find and Replace values.


    Friday, April 18, 2008 10:12 AM

All replies

  • That's the expected behavior. The returned string will start at the given starting index.

    The documentation of Strings.Replace says:

    The return value of the Replace function is a string that begins at the position specified by Start and concludes at the end of the Expression string, with the substitutions made as specified by the Find and Replace values.


    Friday, April 18, 2008 10:12 AM
  • Now I know that it is not a bug.

     

    Thanks.

     

    Friday, April 18, 2008 12:28 PM