[Mono-devel-list] StringBuilder error

Ben Maurer bmaurer at ximian.com
Tue Jun 21 18:43:14 EDT 2005


On Tue, 2005-06-21 at 11:52 +0400, Vorobiev Maksim wrote:
> Good day.
>  
> I thing I found an error in StringBuilder class for Replace method:
> 
> public StringBuilder Replace( string oldValue, string newValue, int
> startIndex, int count ) 
> 
> An error occurs then we replace substring and the length of result
> string becomes longer then before operation. This is because is this
> case the end-of-string is replaced and there is no tailing \0. The
> garbage present in the result. For example, the next code shows the
> problem:
> 
> StringBuilder sb = new StringBuilder ();
> sb.Append ("This, is, a, list");
> Console.WriteLine( sb );
> sb.Replace (",", " comma-separated ", 0, 13);
> Console.WriteLine( sb );
> 
> The result string in the second print will be 'This  comma-separated'
> and a garbage at the tail....:(
> Problem was found for version 1.1.7, but the same code still present for
> 1.1.8. BTW, MS .NET doesn't have this bug.
> We have a patch for this problem. I append it to the message. Please, if
> it's ok for everyone, supply it to the common source base.

I checked this into svn. Thanks for the great patch!

-- Ben




More information about the Mono-devel-list mailing list