[erlang-questions] How can I break this string into a list of strings?
lloyd@REDACTED
lloyd@REDACTED
Sun Dec 25 03:52:17 CET 2016
Thanks all, but apologies.
I misstated my problem.
What I'm really need to do is convert:
"<h1>Hello!</h1>\n <h2>How are you?</h2>\n <p>Some text\n> and more text.</p>"
Into:
["<h1>Hello!</h1>", "<h2>How are you?</h2>", "<p>Some text\n and more text.</p>"]
Such that:
length(MyString) returns 3
or
[length(String) || String <- MyString] returns [N1, N2,N3]
re and string:tokens/2 got a bit muddled in my mind.
Thanks again,
LRP
-----Original Message-----
From: "Kenneth Lakin" <kennethlakin@REDACTED>
Sent: Saturday, December 24, 2016 5:42pm
To: erlang-questions@REDACTED, "Lloyd R. Prentice" <lloyd@REDACTED>
Subject: Re: [erlang-questions] How can I break this string into a list of strings?
On 12/24/2016 01:34 PM, lloyd@REDACTED wrote:
> I don't want those pesky escaped quotes at the end of the heads. I want the real deal.
Does it help you to know that those double-quotes aren't _actually_
escaped and that the backslashes are added by the pretty-print code?
Continuing on with your example:
2> B=re:replace(Copy, [$>,$\n], [$>,$",$,,$"], [global, {return, list}]).
%re:replace output elided
3> lists:nth(16, B).
34
4> lists:nth(15, B).
62
ASCII 34 is '"'. ASCII 62 is '>'. There's no "\" in the output, which
would be ASCII 92:
5> lists:foldl(fun(92, Acc) -> Acc ++ [92]; (_, Acc) -> Acc end, [], B).
[]
The pretty-printer is a nice feature (AFAICT, anything the
pretty-printer prints is valid Erlang), but I suspect that being
startled by its escaping is a rite of passage.
More information about the erlang-questions
mailing list