سؤال

I have to format the programming code that several people have dumped in. So I have to make sure that there are not double spaces, all classes have a comment etc.. Anyways I am having a hard time creating this find and replaces because of the new line... In other words some chunks have:

   // this is some comment \r\n
   // some other line \r\n

other chunks just have:

  // bla bla bla \n
  // bla bla bla \n

other chunks

 // bla bla bla \r
 // bla bla bla \r

lastly other chunks have

 // bla bla \n\r
 // bla bla \n\r

because of this differences I am having a harder time to create the regexes.

So my question is how can I replace all possibilities (\r\n, \n, \r, \n\r) into \r\n? so that:

        var a = "\n\r\n\rHelloWorld";
        var b = "\r\n\n\rHelloWorld";
        var c = "\r\rHelloWorld";
        var d = "\n\nHelloWorld";

all turn out to be: "\r\n\r\nHelloWorld"

note that all variables a, b, c, and d =

->
->
-> HelloWorld

they all look the same on visual studio...

هل كانت مفيدة؟

المحلول

I think what you need to do is replace CR possibly followed by LF, or LF possibly followed by CR:

Search: \r\n?|\n\r?

Replace: \r\n

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top