我有一个List<char>
在stripchars
中。这些字符不应该出现在字符串text
中。所以我把它变成了可变的。
所以我做了这样的事情:
stripchars |> Seq.iter(
fun x ->
text <- text.Replace(x, ' ')
)
然后我收到了一个错误提示,说text是一个可变变量在无效的方式下使用。现在我去看这篇帖子,并得出以下结论:
let s = ref text
stripchars |> Seq.iter(
fun ch ->
printfn "ch: %c" ch
printfn "resultant: %s" !s
s := (!s).Replace(ch, ' ')
)
这样仍不能改变text
的状态。正确的方法是什么?