D
D
distmemory2019-11-13 22:32:51
ASP.NET
distmemory, 2019-11-13 22:32:51

Replace does not work in C# with HTML text. Already broke my head, how to fix it?

Reading text from a file

using (StreamReader SourceReader = File.OpenText("EmailTemplates/individual_register.html"))
            {
                bodyBuilder.HtmlBody = SourceReader.ReadToEnd();
            }

<html style="width:100%;font-family:roboto, 'helvetica neue', helvetica, arial, sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;padding:0;Margin:0;">
 <head> 
  <meta charset="UTF-8"> 
  <meta content="width=device-width, initial-scale=1" name="viewport"> 
  <meta name="x-apple-disable-message-reformatting"> 
  <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
  <meta content="telephone=no" name="format-detection"> 
  <title>Новое письмо 2</title> 
 
 <link href="https://fonts.googleapis.com/css?family=Roboto:400,400i,700,700i" rel="stylesheet">

After reading, the characters '\' and '\n\' appear.
<html style=\"width:100%;font-family:roboto, 'helvetica neue', helvetica, arial, sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;padding:0;Margin:0;\"> <head>   <meta charset=\"UTF-8\">   <meta content=\"width=device-width, initial-scale=1\" name=\"viewport\">   <meta name=\"x-apple-disable-message-reformatting\">   <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">   <meta content=\"telephone=no\" name=\"format-detection\">   <title>Новое письмо 2</title>   <link href=\"https://fonts.googleapis.com/css?family=Roboto:400,400i,700,700i\" rel=\"stylesheet\">

Then I remove the '\' character
bodyBuilder.HtmlBody = bodyBuilder.HtmlBody.Replace("\\", "");

Zero effect

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yuopi, 2019-11-14
@distmemory

You don't need to remove the escape characters here, as they are not actually in the string. These are service characters, try to output the source string to the console or to a file and you will see that they are not there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question