what's the best way to hardcode a multiple-line string?
Little known feature: you can indeed indent string content - by ending each line with a backslash. Leading spaces on the following line are stripped:
let poem = "The lesser world was daubed\n\
By a colorist of modest skill\n\
A master limned you in the finest inks\n\
And with a fresh-cut quill.\n"
You will still need to include \n
or \n\r
at line ends though (as done in the example above), if you want these embedded in your final string.
Edit to answer @MiloDCs question:
To use with sprintf:
let buildPoem character =
sprintf "The lesser world was daubed\n\
By a colorist of modest skill\n\
A master limned %s in the finest inks\n\
And with a fresh-cut quill.\n" character
buildPoem "you"
buildPoem "her"
buildPoem "him"
If you are under F# 3.0, triple-quoted strings may be the answer:
let x = """
myline1
myline2
myline3"""
I'm surprised nobody has mentioned this:
[ "My first line"
"second line"
"another line" ]
|> String.concat "\n"