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"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)