[Mono-bugs] [Bug 41411][Min] New - String.IndexOf(String.Empty) does not return 0;

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Tue, 15 Apr 2003 19:52:18 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by tom@acquist.com.

http://bugzilla.ximian.com/show_bug.cgi?id=41411

--- shadow/41411	Tue Apr 15 19:52:18 2003
+++ shadow/41411.tmp.27606	Tue Apr 15 19:52:18 2003
@@ -0,0 +1,68 @@
+Bug#: 41411
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Minor
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: tom@acquist.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: String.IndexOf(String.Empty) does not return 0;
+
+Description of Problem:
+String.IndexOf(String.Empty) returns -1, but it should return 0.  Also, the
+IndexOf methods that take the sindex argument should return sindex when the
+string to search for is the empty string.
+
+
+Steps to reproduce the problem:
+Compile and run the following:
+
+using System;
+
+public class Empty
+{
+
+public static void Main()
+{
+	string str = "This is a string.";
+	
+	if(str.IndexOf("") == -1)
+	{
+		Console.WriteLine("Empty string isn't found!");
+	}
+	else
+	{
+		Console.WriteLine("Empty string is found.");
+	}
+}
+
+}
+
+Actual Results:
+Prints "Empty string isn't found!".
+
+
+Expected Results:
+It should print "Empty string is found.".
+
+
+How often does this happen? 
+Always.
+
+
+Additional Information:
+According to the spec, String.IndexOf(""); should return 0, as the empty
+string is always found at the start of a string.  The spec also says that
+the IndexOf method should return sindex for an empty string, so this is an
+issue in more than just the single argument IndexOf.
+No fix is provided, as IndexOf ends with a call to InternalIndexOf where
+the issue probably lies.  Basically, it would be something to the effect of
+"if(value.Length == 0){return sindex;}".