在 F# 交互式中显示完整字符串 window

Display full string in F# interactive window

如果我在 Visual Studio 代码

中将以下内容键入 fsx
let longString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

and 运行 F# interactive on it by highlighting and pressing Alt+Enter, interactive [=中的输出32=] 是

- let longString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepte- ur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";;
val longString : string =
  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "+[384 chars]

或截图:

如何让 F# 交互式 window 显示完整的字符串?有捷径吗?

我知道 this post,但据我所知这是不同的,因为字符串不是延迟求值的。

printfn 将完整打印:

printfn "%s" longString

或者,您可以更改 fsi 对象属性,例如:

fsi.PrintWidth <- 1000;;

此外,您可以使用 AddPrinter:

fsi.AddPrinter (fun (s:string) -> s)

这是文档:https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/fsharp-interactive-options#f-interactive-structured-printing

如果只是为了testing/debugging: 如果您在 VSC 中,您可以像您提到的那样以交互方式 运行 您的脚本。您可以通过使用交互式终端并键入(在所述交互式终端中)

来利用它
longString;;

//output
val it : string =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

然后这将显示整个字符串,并且在大多数情况下就足够了(因为无论如何您都不希望用不必要的输出使脚本混乱)。