[英]String editing issues in FSharp F#
一种容易获得的功能性方法是使用匹配项,但重新生成新的字符串。
您可能还想使用Some / None(如果您查看函数的签名,它会为您提供一个作为函数结果的选项字符串),这是一种实用的编写方法,但是如果您需要一个空链,也可以返回一个)。 请参阅F#的圣经fsharpforfunandprofit.com
一些评论:
https://fsharpforfunandprofit.com/posts/the-option-type/
let stringContains (word:string) (hidden:string) (guess:string) =
match word.IndexOf(guess) with
| -1 -> None
| ind -> match (hidden.Length < ind) with
| true -> Some (guess)
| false -> Some (hidden.Substring(0, ind) + guess)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.