[英]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.