Last post Oct 02, 2009 02:47 PM by atconway
Oct 02, 2009 08:50 AM|Lorddog|LINK
just found out that replace(string, ... does not do the same as string.replace(...
when my string variable was an empty str the first one returns "nothing" and the second returns an empty string (as expected).
just sloppy coding anyhow, it was a function that was converted from classic asp and never rewritten properly.
dim str as string = ""
str = Replace(str, "'", "") 'makes str = nothing
str = str.Replace("'", "") ' makes str = ""
Oct 02, 2009 02:47 PM|atconway|LINK
Yes that is correct. 'Replace' comes from the Microsoft.VisualBasic library and has a different way of processing the string. Read this about the 'Replace' VB method from the MSDN:
"If Expression is zero-length or Nothing, or Start is greater than length of Expression The 'Replace' returns 'Nothing'"
Replace Function (Visual Basic):
String.Replace is from the core System library and here are the comments from the MSDN on the return value:
"A String equivalent to this instance but with all instances of oldValue replaced with newValue."
String.Replace Method (String, String):
So as you can see, there is a good lesson to show here. Once can not assume that (2) similar functions or methods in the framework may not behave the same even if they are similar in purpose.