[Mono-devel-list] StringBuilder error

Vorobiev Maksim MVorobiev at croc.ru
Tue Jun 21 03:52:50 EDT 2005


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: StringBuilder.diff
Type: application/octet-stream
Size: 805 bytes
Desc: StringBuilder.diff
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050621/14ed2403/attachment.obj 


More information about the Mono-devel-list mailing list