连接字符串数组,并在另一个字符串前添加F#

|| 例如,我有一个字符串数组行
lines = [| \"hello\"; \"world\" |]
我想创建一个字符串行,该行将以\“ code = \”字符串开头的行中的元素连接起来。例如,我需要从lines数组中获取字符串
code=\"helloworld\"
。 我可以用此代码获得连接的字符串
let concatenatedLine = lines |> String.concat \"\" 
并且我测试了此代码以在\“ code = \”字符串之前添加如下代码,但是出现了
error FS0001: The type \'string\' is not compatible with the type \'seq<string>\'
错误。
let concatenatedLine = \"code=\" + lines |> String.concat \"\" 
这怎么了?     
已邀请:
        
+
|>
绑定更牢固,因此您需要添加一些括号:
let concatenatedLine = \"code=\" + (lines |> String.concat \"\")
否则,编译器将解析表达式,如下所示:
let concatenatedLine = ((\"code=\" + lines) |> (String.concat \"\"))
                         ^^^^^^^^^^^^^^^
                         error FS0001 
    
        我认为您想尝试以下方法(正向管道运算符的优先级较低)
let concatenatedLine = \"code=\" + (lines |> String.concat \"\" )
    

要回复问题请先登录注册