Ale*_*kiy 0 .net c# globalization localization cultureinfo
我只是在寻找这两种方法产生不同结果的任何例子.首先,我访问msdn页面,并通过微小的更改运行代码
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));
}
}
Run Code Online (Sandbox Code Playgroud)
但在这里我遇到了一个问题:这段代码为所有现有文化产生相同的输出ToLower和ToLowerInvariant调用.
所以问题是:有任何字符串可以为此测试产生不同的结果吗?
尝试土耳其点缀?:
var culture = new CultureInfo("tr-TR");
string test = "?";
if (test.ToLower(culture) == test.ToLowerInvariant())
Console.WriteLine("Same");
else
Console.WriteLine("Different"); // Prints this!
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3928 次 |
| 最近记录: |