[Mono-bugs] [Bug 41397][Min] New - StringBuilder.Replace loses left side of replacement.

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Tue, 15 Apr 2003 15:46:42 -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=41397

--- shadow/41397	Tue Apr 15 15:46:42 2003
+++ shadow/41397.tmp.21741	Tue Apr 15 15:46:42 2003
@@ -0,0 +1,82 @@
+Bug#: 41397
+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: StringBuilder.Replace loses left side of replacement.
+
+Description of Problem:
+When startIndex > 0, StringBuilder.Replace(string, string, int, int) will
+lose the part of the string to the left side of startIndex.
+
+
+Steps to reproduce the problem:
+Compile and run the following:
+
+using System;
+using System.Text;
+
+public class SBError
+{
+
+public static void Main()
+{
+	StringBuilder SBError = new StringBuilder();
+	SBError.Append("First");
+	SBError.Append("Second");
+	SBError.Append("Third");
+	SBError.Replace("Second", "Gone", 2, SBError.Length-2);
+	Console.WriteLine(SBError.ToString());
+
+	StringBuilder SBError2 = new StringBuilder();
+	SBError2.Append("This, is, a, list");
+	SBError2.Replace(",", "comma-separated", 11, SBError2.Length-11);
+	Console.WriteLine(SBError2.ToString());
+}
+
+}
+
+Actual Results:
+It prints:
+
+rstGoneThird
+ comma-separated list.
+
+
+
+Expected Results:
+It should print:
+
+FirstGoneThird
+This, is, a comma-separated list.
+
+
+How often does this happen? 
+Always.
+
+
+Additional Information:
+Adding the line
+
+newStringB.Append(startString.Substring(0, lastIndex));
+
+immediately following the lines
+
+int nextIndex = startIndex; // Where to start the next search
+
+int lastIndex = nextIndex;  // Where the last search finished
+
+appears to fix the issue by immediately appending the left side of the
+string prior to replacement.  This fix solves the issue at hand, but has
+not been fully tested.