Why does TrimStart trims a char more when asked to trim "PRN.NUL" ?

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-05-14T19:19:40Z Indexed on 2010/05/14 19:24 UTC
Read the original article Hit count: 229

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#