如何在C#中比较两个字符串? [英] how to compare two strings in c#?
本文介绍了如何在C#中比较两个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在c#中比较两个字符串?
how to compare two strings in c#?
推荐答案
^ ]
CP答案
compare strings[^]
CP answers
这可能会有所帮助,
如何:比较字符串 [
It might be helpful,
How to: Compare Strings[^]
:)
请尝试以下代码.
用于区分大小写.
Try as below code.
For Case Sensitive Comparison.
string string1 = "Something";
string string2 = "Something";
if (string1.Equals(string2,StringComparison.Ordinal))
{
//Strings are Equal
}
else
{
//Strings are not Equal
}
用于不区分大小写的比较.
For Case Insensitive Comparison.
string string1 = "Something";
string string2 = "Something";
if (string1.Equals(string2,StringComparison.OrdinalIgnoreCase))
{
//Strings are Equal
}
else
{
//Strings are not Equal
}
这篇关于如何在C#中比较两个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文