Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to compare part of 2 strings in c#

string phoneNumber1 = 01234567899;
string PhoneNumber2 = +441234567899;

How do I compare last 10 digits only of these 2 strings in c#? These are 2 different formats of UK phone numbers for same number. I wan’t to compare them to find if they’re matching.

Thanks in advance

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Approach with Reverse() and Take()

string number1 = "01234567899";
string number2 = "+441234567899";

bool result = number1.Reverse().Take(10).SequenceEqual(number2.Reverse().Take(10));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading