0

I'm looping through some records, and flagging errors if there are difference using .Except Everything works great, except I want to make a more user friendly error message.

For failedTests, I only want to add the first characters of each line in errorRecords (There may be several lines.) If I do failedTests = string.Join("\n", errorRecords).Substring(0,10); I only get the substring for the first row. I need the substring for each row.

Is there a quick and dirty way to do this?

  var errorRecords = sourceList.Except(destList);
  failedTests = string.Join("\n", errorRecords);

1 Answer 1

1

I recommend using a simple LINQ statement to create a modified version of each row, then passing that into the Join.

failedTests = string.Join("\n", errorRecords.Select(r => r.Substring(1, 10));
Sign up to request clarification or add additional context in comments.

4 Comments

@AlexD: Yeah, I was basing it on the OP. Not sure if he had that part intentionally.
"the first ten characters", so perhaps not intentional.
Thanks, guys. I'm still playing around with the exact length. But I'll make sure to start it at 0. Cheers!
and you don't need to materialize errorRecords if you do failedTests = string.Join("\n", sourceList.Except(destList).Select(r => r.Substring(0, 10));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.