Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F#不区分大小写的字符串比较_F# - Fatal编程技术网

F#不区分大小写的字符串比较

F#不区分大小写的字符串比较,f#,F#,在F#中是否有一种语法上比下面更干净的方法来进行不区分大小写的字符串比较 System.String.Equals("test", "TeSt", System.StringComparison.CurrentCultureIgnoreCase) 写一个扩展方法来缩短它怎么样。另外,你可以使用力学: > type System.String with - member s1.icompare(s2: string) = - System.String.Equals(s1, s

在F#中是否有一种语法上比下面更干净的方法来进行不区分大小写的字符串比较

System.String.Equals("test", "TeSt", System.StringComparison.CurrentCultureIgnoreCase)

写一个扩展方法来缩短它怎么样。

另外,你可以使用力学:

> type System.String with
-   member s1.icompare(s2: string) =
-     System.String.Equals(s1, s2, System.StringComparison.CurrentCultureIgnoreCase);;
> "test".icompare "tEst";;
val it : bool = true

对于任何感兴趣的用户,都可以使用以下部分活动模式:

let (|InvariantEqualI|_|) (str:string) arg = 
  if String.Compare(str, arg, StringComparison.InvariantCultureIgnoreCase) = 0
  then Some() else None
let (|OrdinalEqualI|_|) (str:string) arg = 
  if String.Compare(str, arg, StringComparison.OrdinalIgnoreCase) = 0
  then Some() else None

很好的建议,只是为了扩展您的答案,我使用了下面的let(=?)s1s2=System.String.Equals(s1,s2,System.StringComparison.CurrentCultureInoRecase)
// Contains substring
(str1.ToUpper()).Contains (str2.ToUpper())
// Equality
(str1.ToUpper()).Contains (str2.ToUpper())