I need help with a program that im using to verify a user's names. there has to be a certain level of leniency to accept differences like hyphens, spaces and apostrophes. Currently im removing useless characters to compare the strings but names of completely different characters with the same length are being Ok'd. how do i check to see the names are suing similar characters. after the useless ones have been removed and mushed together.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace name_v
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter first name");
string firstname = Console.ReadLine();
Console.WriteLine("Enter 2nd name");
string secondname = Console.ReadLine();
if (firstname == secondname)
{
Console.WriteLine("Names are exactly the same");
Console.ReadLine();
}
else
{
Console.WriteLine("press enter to Compare");
Console.ReadLine();
int numFirstName = firstname.Length;
int numSecondName = secondname.Length;
Console.WriteLine("# in 1st = " + numFirstName);
Console.WriteLine("# in 2nd = " + numSecondName);
Console.ReadLine();
firstname = firstname.Replace(" ", "").Replace("-", "").Replace("'", "").Replace(".", "").ToUpper();
secondname = secondname.Replace(" ", "").Replace("-", "").Replace("'", "").Replace(".", "").ToUpper();
Console.WriteLine("Names to be compared as");
Console.WriteLine(firstname);
Console.WriteLine(secondname);
numFirstName = firstname.Length;
numSecondName = secondname.Length;
Console.WriteLine("# in 1st = " + numFirstName);
Console.WriteLine("# in 2nd = " + numSecondName);
Console.ReadLine();
int nameLengthDif = numFirstName - numSecondName;
if (firstname == secondname)
{
Console.WriteLine("Names are the same");
Console.ReadLine();
}
else
{
Console.WriteLine("Names are not the same");
Console.ReadLine();
if (nameLengthDif < 3)
{
Console.WriteLine("But Close enough");
Console.ReadLine();
}
else
{
Console.WriteLine("And not Close enough");
Console.ReadLine();
}
}
}
}
}
}