gpt4 book ai didi

c# - ToLower 与 ToLowerInvariant

转载 作者:行者123 更新时间:2023-12-05 08:57:31 29 4
gpt4 key购买 nike

我只是在寻找这两种方法产生不同结果的任何例子。首先,我访问msdn page , 并从中运行代码并稍作更改

using System;
using System.Globalization;
using System.Linq;

class Program
{
static void Main()
{
string[] words = { "Tuesday", "Salı", "Вторник", "Mardi",
"Τρίτη", "Martes", "יום שלישי",
"الثلاثاء", "วันอังคาร" };
Console.BufferHeight = 1000;
var test = CultureInfo.GetCultures(CultureTypes.AllCultures)
.Select(ci =>
{
string[] wordsToLower = words.Select(x => x.ToLower(ci)).ToArray();
string[] wordsToLowerInvariant = words.Select(x => x.ToLowerInvariant()).ToArray();
return new
{
Culture = ci,
ToLowerDiffers = !wordsToLower.SequenceEqual(wordsToLowerInvariant)
};
})
.ToArray();
foreach (var x in test)
{
Console.WriteLine("Culture {0}, ToLower and ToLowerInvariant produces different results: {1}", x.Culture, x.ToLowerDiffers);
}
Console.WriteLine();
Console.WriteLine("Difference exists for any ToLower call: {0}", test.Any(x => x.ToLowerDiffers));
}
}

但这里我遇到了一个问题:此代码在所有现有文化中为 ToLowerToLowerInvariant 调用生成相同的输出。

那么问题是:是否有任何字符串会为此测试产生不同的结果?

最佳答案

试试土耳其语点缀 İ:

var culture = new CultureInfo("tr-TR");

string test = "İ";

if (test.ToLower(culture) == test.ToLowerInvariant())
Console.WriteLine("Same");
else
Console.WriteLine("Different"); // Prints this!

关于c# - ToLower 与 ToLowerInvariant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30778301/

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