A coworker was puzzled when he tracked down this bug today. If you look up the letter Þ, it is the thorn letter and it sounds like ‘th’. It came as as a surprise that “TH”.StartsWith “Þ” = true. The reason it is true is that String.StartWith uses StringComparison.CurrentCulture. The solution was to specify the StringComparison: "TH".StartsWith("Þ", StringComparison.Ordinal). The reason this was unexpected was because String.Equals uses StringComparison.Ordinal by default. The .NET String API just seams inconsistent in this regard.
open Microsoft.VisualStudio.TestTools.UnitTesting
open System
[<TestClass>]
type ThornTest() =
[<TestMethod>]
member x.TestDefault() =
Assert.IsFalse <| "TH".StartsWith "Þ" // fail
[<TestMethod>]
member x.TestCurrentCulture() =
Assert.IsFalse <| "TH".StartsWith("Þ", StringComparison.CurrentCulture) // fail
[<TestMethod>]
member x.TestOrdinal() =
Assert.IsFalse <| "TH".StartsWith("Þ", StringComparison.Ordinal) // pass
I created these unit tests using Visual Studio 11 Beta and ran them using its new Unit Test Explorer window. Program.fs containing the unit tests should work on VS 10 too, but you will need to create a new project.