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?
Asked
Active
Viewed 87 times
2 Answers
3
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
- 1,421,763
- 867
- 9,128
- 9,194
2
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
- 41,404
- 5
- 117
- 189