C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
And: The result is that the order is unnatural and hard to scan. The period should be ignored.
Info: In the second query, we implement the code that ignores the leading parenthesis and period characters before considering the strings.
TrimStart: We call TrimStart on the identifier in the orderby part of the clause. The sort key does not include leading punctuation.
TrimEnd, TrimStartorderbyC# program that sorts, ignores characters
using System;
using System.Linq;
class Program
{
static void Main()
{
string[] elements = { "A", "(Z)", ".NET", "NO" };
{
var sorted = from element in elements
orderby element
select element;
foreach (var element in sorted)
{
Console.WriteLine(element);
}
}
Console.WriteLine("---");
{
var sorted = from element in elements
orderby element.TrimStart('(', '.')
select element;
foreach (var element in sorted)
{
Console.WriteLine(element);
}
}
}
}
Output
(Z)
.NET
A
NO
---
A
.NET
NO
(Z)
And: This can lead to more natural, usable sorted arrays, and better interface usability.