I'd like to do something like this
String.concat '\n' [str1; str2 ... strn]
so I can print in a file. But ocaml doesn't allow me to do that. What can I do?
The (^) binary operator concatenates two strings.
In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.
In Java, String concatenation forms a new String that is the combination of multiple strings. There are two ways to concatenate strings in Java: By + (String concatenation) operator. By concat() method.
There are two ways to do this: Add double quotation marks with a space between them " ". For example: =CONCATENATE("Hello", " ", "World!"). Add a space after the Text argument.
String.concat "\n" [str1; str2 ... strn]
works fine. The problem is that you used '\n'
, which is a character literal, not a string. Example:
# String.concat '\n' ["abc"; "123"];;
Error: This expression has type char but an expression was expected of type
string
# String.concat "\n" ["abc"; "123"];;
- : string = "abc\n123"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With