I am using epgsql to query a database, in Erlang. It returns string results including quotation marks surrounding them like this: "what_was_in_the_row". How can I remove these quotation marks before working with the result?
the control format ~p (pretty print) keeps information about the type of the variables that are printed. You are printing a string, which is, in erlang, a standard integer list made of printable characters for example [101,102,103] is displayed as "efg" in the shell.
If you call io_lib:format("~p",[[101,102,103]])., you will get the result ["\"efg\""] which needs some explanation.
io_lib:format/2,\" is an escape sequence that represents the single character "You can evaluate the length of each string to verify the difference:
If you want to get the string without the surrounding quotes, you must use the control format ~s
1> [Res] = io_lib:format("~s",[[101,102,103]]).
["efg"]
2> length(Res).
3
3> [Res] = io_lib:format("~s",[Res]).
["efg"]
Of course, the last line shows that my example is stupid. With io_lib:format("~s ~s!",["Hello","world"]). or any more complex formatting, the result is of type chars(): a list of char() or chars().
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