如何将一个字符串与C#中数据库中的另一个字符串匹配?

问题描述 投票:0回答:1

我遇到一个问题,我有两个字符串,其中一个字符串来自作为JSON对象返回的QR码值,第二个字符串来自数据库,如果试图将它们匹配在一起,数据库中的一个字符串是相同的,请继续。如果不是,请显示一条消息。这就是我在下面尝试过的。因此,有人通过检查第二个字符串中是否存在第一个字符串来帮助我解决此问题吗?谢谢您的帮助。

这是我的代码:

    var result = JsonConvert.DeserializeObject<dynamic>(barCodeValue);
    var gettingTheName = (string)result.name.Value;
    TextHeader.text = gettingTheName;

    var matchingLink = new WebClient().DownloadString("https://PROJECT.URL.firebaseio.com/name.json");

    if (matchingLink.Equals(gettingTheName))

    {
        SceneManager.LoadScene("Verify");
        Debug.Log("Success");


    }     
    else if (matchingLink != barCodeValue) 

    {
          EditorUtility.DisplayDialog("No matched user", "Sorry, there is no user " +  gettingTheName + " matched ", "OK"); 
         SceneManager.LoadScene("QRCode");


    }

    Audio.Play();


}); 
c# string-comparison
1个回答
0
投票
string gettingTheName = // however you populate gettingTheName, but should be a JSON string.
string matchingLink = // however you populate matchingLink , but should be a JSON string.

var result1 = JsonConvert.DeserializeObject<dynamic>(gettingTheName);
var result2 = JsonConvert.DeserializeObject<dynamic>(matchingLink);

if (result1.name != null && result2.name != null && result1.name == result2.name)
{
    string names = "Names Match";
}
else
{
    string names = "Names Do Not Match";
}
© www.soinside.com 2019 - 2024. All rights reserved.