How to change F# Interactive newline character

℡╲_俬逩灬. 提交于 2019-12-12 09:53:46

问题


In a .fs file a newline is denoted by \r\n, but in the F# Interactive window it is \n.

In a problem I'm currently trying to solve, the length of a multiple line literal string matters. So a problem arises when I am testing code in the F# Interactive window, because the length of the string is different from in normal execution.

I hope there is an option to change the newline 'character' in F# Interactive to \r\n, but I can't find it. Does anyone know where I can achieve this, or some other workaround?


回答1:


You can use conditional compilation to handle this:

#if INTERACTIVE
  text.Replace("\n", System.Environment.NewLine)
#endif

I don't know of a way to change it in fsi. Another option would be to remove, or normalize, the newlines regardless of the execution environment. If the exact length is that important, it might be good to do anyway.

EDIT

If the newlines are only there for readability, you can end each line with a backslash. The backslash, newline, and leading whitespace on the following line are removed at compile time.

let text = "a\
            b"
printfn "%s" text //"ab"

This works the same in VS and FSI. I'm assuming you're sending bits of code to FSI via Alt+Enter or Alt+'.



来源:https://stackoverflow.com/questions/7393658/how-to-change-f-interactive-newline-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!