如何更改F#交互式换行符 [英] How to change F# Interactive newline character

查看:124
本文介绍了如何更改F#交互式换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.fs文件中,换行符用\r\n表示,但是在F#Interactive窗口中,换行符是\n.

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

在我当前要解决的问题中,多行文字字符串的长度很重要.因此,当我在F#Interactive窗口中测试代码时会出现问题,因为字符串的长度与正常执行中的字符串不同.

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.

我希望可以将F#Interactive中的换行符'character'更改为\r\n,但是我找不到它.有谁知道我可以在哪里实现这一目标,或者其他解决方法?

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?

推荐答案

您可以使用条件编译来解决此问题:

You can use conditional compilation to handle this:

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

我不知道在fsi中进行更改的方法.另一个选择是不管执行环境如何,都删除或标准化换行符.如果确切的长度那么重要,那还是可以的.

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.

如果换行仅出于可读性考虑,则可以在每行末尾加反斜杠.编译时将删除下一行中的反斜杠,换行符和前导空格.

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"

这在VS和FSI中相同.我假设您是通过Alt+EnterAlt+'向FSI发送一些代码.

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

这篇关于如何更改F#交互式换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆