Home All Groups Group Topic Archive Search About

Microsoft.VisualBasic.Replace bug

Author
4 Oct 2006 5:56 PM
Harry F. Harrison
In VS 2003, If an empty string is passed into the 1st parameter, the Replace
function returns Nothing.

Example:

Dim strResults As String = ""
strResults = Microsoft.VisualBasic.Replace("", "AND", "And", , ,
CompareMethod.Binary)

looking at strResults in the debugger shows it having a value of nothing
after executing the Replace function.

The documentation specifically says that it should return an empty string.

Return Values
Replace returns the following values:

      If Replace returns
      Expression is zero-length Zero-length string ("")
      Find is zero-length Copy of Expression
      Replace is zero-length Copy of Expression with no occurrences of Find
      Start is greater than length of expression Zero-length string
      Count is 0 Copy of Expression

Author
4 Oct 2006 8:48 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Harry F. Harrison" <harry***@hotmail.com> schrieb:
> In VS 2003, If an empty string is passed into the 1st parameter, the
> Replace function returns Nothing.
>
> Example:
>
> Dim strResults As String = ""
> strResults = Microsoft.VisualBasic.Replace("", "AND", "And", , ,
> CompareMethod.Binary)
>
> looking at strResults in the debugger shows it having a value of nothing
> after executing the Replace function.
>
> The documentation specifically says that it should return an empty string.

Yes, this is a bug in the implementation.  Unfortunately Microsoft decided
to change the method specification instead of fixing the implementation in
VB 2005:

Check out this discussion:

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/browse_frm/thread/41cbc41c1c2331ac>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>