Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# case insensitive string compare

Tags:

f#

Is there a syntactically cleaner way to preform a case insensitive string comparison in F# than the following

System.String.Equals("test", "TeSt", System.StringComparison.CurrentCultureIgnoreCase)
like image 716
Joshua Avatar asked Dec 20 '09 19:12

Joshua


2 Answers

Also, you can use F# type extensions mechanics:

> type System.String with
-   member s1.icompare(s2: string) =
-     System.String.Equals(s1, s2, System.StringComparison.CurrentCultureIgnoreCase);;
> "test".icompare "tEst";;
val it : bool = true
like image 110
ssp Avatar answered Sep 20 '22 02:09

ssp


How about writing an extension method to make this shorter.

like image 36
Darin Dimitrov Avatar answered Sep 21 '22 02:09

Darin Dimitrov