C # Regex Replace How to add text at the end of each line (C #)

I was looking for a site for this simple problem but cannot find the answer.

I have a multi-line string. I want to add a constant line to the end of each line. I am using Regex.Replace but am running into problems. I tried replacing as follows.

   Pattern             Replace With
-------------------------------------------
    $                   Text
    ($)                 Text$1
    \n                  Text
    \n                  Text\n
    (\n)                Text$1

But none of these works. In all cases, several lines are combined into one line. How can i do this?

+3
source share
1 answer

You must be able to:

string newString = oldString.Replace("\r\n", "Text\r\n");

replace the text with the line you want to add at the end of each line

+1
source

Source: https://habr.com/ru/post/1750762/


All Articles