gpt4 book ai didi

C# 字符串比较 : Difference between CurrentCultureIgnoreCase and InvariantCultureIgnoreCase

转载 作者:IT王子 更新时间:2023-10-29 04:06:07 26 4
gpt4 key购买 nike

在C#中做字符串比较时,和a有什么区别

string test = "testvalue";
test.Equals("TESTVALUE", StringComparison.CurrentCultureIgnoreCase);

string test = "testvalue";
test.Equals("TESTVALUE", StringComparison.InvariantCultureIgnoreCase);

...无论如何,包含该额外参数是否重要?

最佳答案

其他帖子给出了很好的建议,但我认为展示一个例子可能会更好:

using System;
using System.Globalization;
using System.Threading;

class Test
{
static void Main()
{
CultureInfo turkish = CultureInfo.CreateSpecificCulture("tr");
Thread.CurrentThread.CurrentCulture = turkish;

// In Turkey, "i" does odd things
string lower = "i";
string upper = "I";

// Prints False
Console.WriteLine(lower.Equals(upper,
StringComparison.CurrentCultureIgnoreCase));
// Prints True
Console.WriteLine(lower.Equals(upper,
StringComparison.InvariantCultureIgnoreCase));
}
}

(毫无疑问,还有很多其他情况 - 这只是我想到的第一个。)

关于C# 字符串比较 : Difference between CurrentCultureIgnoreCase and InvariantCultureIgnoreCase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/417954/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com