在某些文化中,资本“我”有什么问题?我发现在某些文化中无法在特殊条件下找到 - 如果你正在寻找带有标志RegexOptions.IgnoreCase的[a-z]。以下是示例代码:
var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
var allLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var allLettersCount = allLetters.Length;
foreach (var culture in allCultures)
{
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
var matched = string.Empty;
foreach (var m in Regex.Matches(allLetters, "[A-Za-z0-9]", RegexOptions.IgnoreCase))
matched += m;
var count = matched.Length;
if (count != allLettersCount)
Console.WriteLine("Culture '{0}' - {1} missing; Matched: {2}", culture.Name, (allLettersCount - count).ToString(), matched);
}
输出是(注意每行中缺少资本I):
Culture 'az' - 1 missing; Matched: ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Culture 'az-Cyrl' - 1 missing; Matched: ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Culture 'az-Cyrl-AZ' - 1 missing; Matched: ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Culture 'az-Latn' - 1 missing; Matched: ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Culture 'az-Latn-AZ' - 1 missing; Matched: ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Culture 'tr' - 1 missing; Matched: ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Culture 'tr-TR' - 1 missing; Matched: ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
有趣的是,如果没有使用标志“IgnoreCase”那么它运行良好,并找到“我”。