Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang - fwrite tilde

Tags:

erlang

If a string contains a ~, I can't seem to print that to standard out.

> A = "/.git".
> io:fwrite(A).
/.gitok

> B = "~/.git".
> io:fwrite(B).
** exception error: bad argument
 in function  io:format/3
    called as io:format(<0.50.0>,"~/.git",[])

How can I print a string with tildes to standard out?

like image 498
steel Avatar asked Oct 20 '25 22:10

steel


1 Answers

If a string contains a ~, I can't seem to print that to standard out.

To format output, you construct a string containing format sequences that start with a ~. Erlang thinks your string contains a format sequence. If you want Erlang to output a literal ~, you can escape it with another ~:

22> io:format("~~/.git~n").
~/.git
ok
like image 116
7stud Avatar answered Oct 25 '25 15:10

7stud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!