Why does TrimStart trims a char more when asked to trim "PRN.NUL" ?
- by James
Here is the code:
namespace TrimTest
{
class Program
{
static void Main(string[] args)
{
string ToTrim = "PRN.NUL";
Console.WriteLine(ToTrim);
string Trimmed = ToTrim.TrimStart("PRN.".ToCharArray());
Console.WriteLine(Trimmed);
ToTrim = "PRN.AUX";
Console.WriteLine(ToTrim);
Trimmed = ToTrim.TrimStart("PRN.".ToCharArray());
Console.WriteLine(Trimmed);
ToTrim = "AUX.NUL";
Console.WriteLine(ToTrim);
Trimmed = ToTrim.TrimStart("AUX.".ToCharArray());
Console.WriteLine(Trimmed);
}
}
}
The output is like this:
PRN.NUL
UL
PRN.AUX
AUX
AUX.NUL
NUL
As you can see, the TrimStart took out the N from NUL. But it doesn't do that for other strings even if it started with PRN.
I tried with .NET Framework 3.5 and 4.0 and the results are same. Are there any explanation on what causes this behavior?