Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.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
String 如何计算f中字符串中的元音#_String_F# - Fatal编程技术网

String 如何计算f中字符串中的元音#

String 如何计算f中字符串中的元音#,string,f#,String,F#,如何计算f#中字符串中的元音 我把你的元音列表改成了字符列表而不是字符串列表。您必须在函数中实际使用inputText参数。在筛选字符串之前,还必须将其转换为字符数组。然后您必须将inputText作为函数的参数。函数参数inputText和变量inputText除了名称之外没有任何共同之处 编辑:分解ISVOMEL函数,并从count中删除inputText参数,而不是使用首选方法>是否使用FSI(F#interactive)?您可以在visualstudio中使用altenter或VS-co

如何计算f#中字符串中的元音

我把你的元音列表改成了字符列表而不是字符串列表。您必须在函数中实际使用
inputText
参数。在筛选字符串之前,还必须将其转换为字符数组。然后您必须将
inputText
作为函数的参数。函数参数
inputText
和变量
inputText
除了名称之外没有任何共同之处

编辑:分解ISVOMEL函数,并从count中删除inputText参数,而不是使用首选方法
>

是否使用FSI(F#interactive)?您可以在visualstudio中使用altenter或VS-code在FSI中运行代码,并在较小的部分中解决类似的问题。它会帮助你更快地学习。
let proj x =
    if Array.contains x [| 'a';'e';'i';'o';'u' |] then 1
    else 0

let count (text: string) =
    text.ToCharArray()
    |> Array.sumBy proj
let inputText = "sdhkjhsakdnadwqerdsdasefds"
let vowels = ['a';'e';'i';'o';'u']
let isVowel =
    fun c -> vowels |> List.contains c

let count =
    String.filter isVowel
    >> String.length

printfn "%A" (count inputText)
let proj x =
    if Array.contains x [| 'a';'e';'i';'o';'u' |] then 1
    else 0

let count (text: string) =
    text.ToCharArray()
    |> Array.sumBy proj