尽管两个字符串相同,但C#.net核心不能标识相同 [英] Eventhough two strings are same , C# .net core is not identifying as same

查看:44
本文介绍了尽管两个字符串相同,但C#.net核心不能标识相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net核心中发现了此问题.我有两个字母数字字符串,全部为大写,中间或结尾都没有空格.

I found this issue in asp.net core. I have two strings alpha numeric, all upper cases, and no spaces either in the middle or ends.

我从 appsettings.json 中获得一个字符串,而其他则在本地分配.当我比较这两个字符串时,应用程序显示它们不相同.

I am getting one string from appsettings.json and other assigning locally. When I compare those two strings, the application is showing they are not the same.

string stringFromAppSetting = Configuration.GetValue<string>("AppSettingValue");

string string_Local = "1B4D3A3C8F63DBE";
bool? areTheySame=null;
if (stringFromAppSetting == string_Local )
{
    areTheySame = true;
}
else
{
    areTheySame = false;
}

我还尝试了 stringFromAppSetting.Equals(string_Local).它仍然表明它们是不相等的.我使用notepad ++检查它们是否不同,但发现它们相同.

I also tried stringFromAppSetting.Equals(string_Local). It still shows they are not equal. I used notepad++ to check if they are different but I found that they are same.

有人可以提出可能的原因吗?

Can somebody please suggest the possible cause.

推荐答案

谢谢大家的回应.出于某种原因,当从appsettings.json文件中接收到字符串时,存在很多隐藏字符.在添加了删除隐藏字符的逻辑之后,它就像一种魅力....

Thank you all for your response. For some reason, lot of hidden characters were present when string was received from appsettings.json file.After adding a logic to remove hidden character, it worked like a charm....

从字符串内部删除隐藏字符

这篇关于尽管两个字符串相同,但C#.net核心不能标识相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆