0
votes

I am replacing my word document content using OpenXML and with the help of regex detecting words in my document and replacing them with new sentences but the problem is that when I have a long string that contains line breaks the work document displays it as a single line. I have searched everywhere and tried all possible solutions. I even tried this

**

string pre = "<w:p><w:r><w:t>";
        string post = "</w:t></w:r></w:p>";
        string lineBreak = "<w:br />";
        string test = pre + "First Line" + lineBreak + "Second Line" + post;
        //
        Regex regexText1 = new Regex("Question");
        docText = regexText1.Replace(docText, @test);

**

But the result shows long tabs between the text of the first line. Please provide a solution. Word Document Result

1

1 Answers

0
votes

Try this one

    string pre = "<w:p><w:r><w:t>";
        string lineBreak ="</w:t><w:br /><w:t>"
                string post = "</w:t></w:r></w:p>";
                string test = pre + "First Line" + lineBreak + "Second Line" + post;
//
        Regex regexText1 = new Regex("Question");
        docText = regexText1.Replace(docText, @test);