How can I spawn normal file from data returned escaped?
example:
"<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n<meta name=\"keywords\" content=
where I want
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content=
term for this I wonder is 'raw string literal' but I can't find a simple answer.
If the data already have the newlines embedded, writing it to the file should work. If it doesn't, parsing a markup language like HTML or XML is hard as hell, so consider using a lib or something to split every node and print them separately to the file as lines (or merge them in a string with '\n's in between, and then print it. Should be faster but the logic a bit more complicated. Good luck
1 Like
Did you want something like this? (As you've guessed, it is indeed called a raw string literal.)
fn main() {
println!("{}", r#"<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="...">
</head>
<body></body>
</html>"#);
}
Solution was so simple!.. the formatter
Instead of
println!( "\n{:?}", res.body);
used
println!( "\n{}", res.body);