views:

62

answers:

2

I am working with some sample code generously given to me by this answer, and when i enter a long string to match it crashes at some point with an IndexOutOfRangeException. What's strange is that when i inspect the string, it appears to be set to the words "System.Char[]". Why does this happen, and how can i fix it?

+3  A: 

I strongly suspect that somewhere you've got:

char[] chars = ...;
string myString = chars.ToString();

instead of

char[] chars = ...;
string myString = new string(chars);
Jon Skeet
+2  A: 

This code:

    var mutated = member.Str.ToCharArray();
    Convert.ToChar((member.Str[ipos] + delta)%123).ToString().CopyTo(0, mutated, ipos, 1);
    member.Str = mutated.ToString();

Should be, as Jon suggests:

    var mutated = member.Str.ToCharArray();
    Convert.ToChar((member.Str[ipos] + delta)%123).ToString().CopyTo(0, mutated, ipos, 1);
    member.Str = new string(mutated);
Barry Kelly
That fixed the problem! thanks!
RCIX