Determine if all characters in a string are the same

Jhorra picture Jhorra · Apr 16, 2013 · Viewed 15.1k times · Source

I have a situation where I need to try and filter out fake SSN numbers. From what I've seen so far if they are fake they're all the same number or 123456789. I can filter for the last one, but is there an easy way to determine if all the characters are the same?

Answer

AShelly picture AShelly · Apr 16, 2013

return (ssn.Distinct().Count() == 1)