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

时间:2019-03-05 15:14:11

标签: visual-studio-code f# f#-interactive vscode-debugger

如果我在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."

并通过突出显示并按 Alt + Enter 在其上运行F#交互式,交互式窗口中的输出为

- 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]

或作为屏幕截图:

screenshot output

如何告诉F#交互式窗口显示完整字符串?有捷径吗?

我知道this post,但据我所知,这在这里是不同的,因为字符串不是惰性计算的。

2 个答案:

答案 0 :(得分:3)

document.getElementById("useTheId").className = 'the new class name';将完全打印它:

from datetime import datetime, timedelta

INTERVAL = timedelta(minutes=3)
last_checked = datetime.now() - INTERVAL

while True:
    now = datetime.now()
    if last_checked <= (now - INTERVAL):
        if not if_active():
            break
        last_checked = now

    # do your thing here
    pass

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

printfn "%s" longString

此外,您可以使用fsi

fsi.PrintWidth <- 1000;;

以下是文档:https://msdn.microsoft.com/en-us/visualfsharpdocs/conceptual/interactive.interactivesession-class-%5bfsharp%5d

答案 1 :(得分:2)

如果仅用于测试/调试: 如果您使用的是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."

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