Cemal Sener

Cemal Sener

  • 1.9k
  • 48
  • 103

Getting my carriage returns back in C# code

Aug 15 2020 2:17 AM
After an auto conversion task of one VB project to C#, tool doing this task dropped all Carriage Returns (\r\n) from my code. Now I have very long and diffucult to read code lines.

Either one by one enter on the desired location of code line to get a break in the line or must use REGEX (I mean Replace Tool of VS with wild chars). REGEX does this job and breaks line where you wanted successfully. But how I calculate the starting location of new line. I do not want new line starting with a nonsense distance to left margin. Let me give example:

string slsqt = "SELECT * FROM SalesTable WHERE Year(SalesDate) > 2001";

Press ENTER on 'Year' in Visual Studio you will get just two lines like these:

string slsqt = "SELECT * FROM SalesTable WHERE
    Year(SalesDate) > 2001";

Nice, it started one TAB ahead from left margin. Well how to do this with REGEX Replace using \r\n ?
How I can calculate and add SPACE to REGEX ?

Brought to you by:

Answers (2)