我使用了以下命令来获取与特定模式匹配的密钥计数,
namespace UKPostCodeConsoleApp
{
class Program
{
static void Main(string[] args)
{
string firstPostCode = "DD81UN";
string secondPostCode = "DN551PT";
Console.WriteLine(ParseToUkPostcode(firstPostCode));
Console.WriteLine(ParseToUkPostcode(secondPostCode));
Console.Read();
}
public static string ParseToUkPostcode(string aPostcode)
{
string finalPostcode = aPostcode;
finalPostcode = finalPostcode.Replace(" ", "").Trim();
string outWardResult = finalPostcode.Substring(0, finalPostcode.Length - 3);
string inWardResult = finalPostcode.Substring(Math.Max(0, finalPostcode.Length - 3));
string postCodeResult = string.Format("{0} {1}", outWardResult, inWardResult);
finalPostcode = postCodeResult;
return finalPostcode;
}
}
}
但是结果与实际值有些不匹配。我的数据库中有六个键。
但结果我得了5分。
我在这里做错了吗??