private void Remove(ref StringBuilder tmpBuilder, ref int removals, int value) { for (int i = 0; i < CurrentText.Length; i++) { char current = CurrentText.GetCharacter16(i); if (current == value) { if (tmpBuilder == null) { tmpBuilder = StringBuilderPool.Rent(CurrentText.Length); // append the data that we were holding onto, // excluding the char we are on currently for (int j = 0; j < i; j++) { tmpBuilder.Append(CurrentText.GetCharacter16(j)); } } removals++; } else if (tmpBuilder != null) // we don't append if there are no changes yet { tmpBuilder.Append(current); } } }