在 F# 中使用 sprintf "%A" 时如何全局控制自动插入的换行符

How can I control globally the automatically inserted linebreaks when using sprintf "%A" in F#

此代码在 f# 程序中(不涉及 fsi!)

let s = sprintf "%A" [1..100]
System.IO.File.WriteAllText ("c:/out.txt", s)

写入内容为

的文件
[1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22;
 23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41; 42;
 43; 44; 45; 46; 47; 48; 49; 50; 51; 52; 53; 54; 55; 56; 57; 58; 59; 60; 61; 62;
 63; 64; 65; 66; 67; 68; 69; 70; 71; 72; 73; 74; 75; 76; 77; 78; 79; 80; 81; 82;
 83; 84; 85; 86; 87; 88; 89; 90; 91; 92; 93; 94; 95; 96; 97; 98; 99; 100]

所以有自动插入的换行符

我需要去掉这些换行符。我该如何控制它?

(fsi.PrintWidth等类似设置不适用,fsi不涉及)

一个补救方法是将宽度设置为一个非常大的值:

sprintf "%10000A"

但是是否可以全局定义默认宽度?

%A 说明符用于明文、人类可读的格式:https://docs.microsoft.com/dotnet/fsharp/language-reference/plaintext-formatting#a-formatting

既然如此,就采取这种自以为是的做法,没办法全局配置。您的解决方法是不使用自以为是的格式的一种方法。另一种方法是编写您自己的函数,将值附加到字符串,然后调用它。

let s = sprintf "%0A" [1..100]

https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/plaintext-formatting#structured-values