Actually, another title for the question would be: how to find the character with the highest alphabetical value for the current culture?
Take a look at the following code:
static void Main(string[] args)
{
var input = new[] { "cote", "côte", "coté", "", "côté" };
var maxString = new string(new[] { char.MaxValue });
var byEnUsCulture = input.OrderBy(i =>
(String.IsNullOrEmpty(i)) ? maxString : i,
StringComparer.Create(new CultureInfo("en-US"), false)).ToList();
var byFrFrCulture = input.OrderBy(i =>
(String.IsNullOrEmpty(i)) ? maxString : i,
StringComparer.Create(new CultureInfo("fr-FR"), false)).ToList();
var byOrdinal = input.OrderBy(i =>
(String.IsNullOrEmpty(i)) ? maxString : i,
StringComparer.Ordinal).ToList();
foreach (var words in new[] { byEnUsCulture, byFrFrCulture, byOrdinal })
{
foreach (var word in words)
{
Console.Write("{0} ", (string.IsNullOrEmpty(word)) ? "xxxx" : word);
}
Console.WriteLine();
}
}
The output of the above is:
xxxx cote coté côte côté
xxxx cote côte coté côté
cote coté côte côté xxxx
But what I'm trying to get is:
cote côte coté côté xxxx
Is it possible to order the words above by the fr-FR
culture info and still output the empty (replaced with xxxx
in the output) values at the end of the collection, all that just by using OrderBy
?
Note: Here's a reference for the expected order.