Menu

replace chars with special chars [CR][LF]

2007-06-01
2012-11-13
  • Nobody/Anonymous

    hi,
    i've not understood how i may replace normal chars with spacial chars like  [CR][LF] becouse special chars not paste inside target field in replace box.
    may you help me?

     
    • Chris Severance

      Chris Severance - 2007-10-01

      I was afraid someone would want this but I didn't build an easy way to do into the Ctrl+R replace tool to prevent the torrent of complaints that would result from people accidentally switching the setting. It takes a real special person to want that feature.

      If you don't mind hacking the NPPTextFX source you can get what you want. Find function GetWindowTextUTF8arm() in POPPAD.C. The first 4 lines are what do the deed.

      hwndEditor: the Notepad++ window
      hwndControl: the find or replace box

      // Get the EOL mode from Notepad++
      int iEolMode=SENDMSGTOED(hwndEditor, SCI_GETEOLMODE, 0, 0);

      // Change the find or replace box to the same EOL mode
      SENDMSGTOED(hwndControl, SCI_SETEOLMODE, iEolMode, 0);

      // brazenly convert the EOL's that anonymous typed to the standard ones
      SENDMSGTOED(hwndControl, SCI_CONVERTEOLS, iEolMode, 0);

      //  if (hwndEditor) {
      //    int iEolMode=SENDMSGTOED(hwndEditor, SCI_GETEOLMODE, 0, 0);
      //    SENDMSGTOED(hwndControl, SCI_SETEOLMODE, iEolMode, 0);
      //    SENDMSGTOED(hwndControl, SCI_CONVERTEOLS, iEolMode, 0);
      //  }

      You can either comment out these lines or you can take advantage of something else. If hwndEditor is NULL then EOL conversion is not performed. Change pfr->hwndEditor to NULL in the two GetWindowTextUTF8arm() calls that use it. Check out the other two calls which already have NULL there.

      GetWindowTextUTF8arm(NULL/*pfr->hwndEditor*/,GetDlgItem(hDlg,IDC_EDTREPLACE),&pfr->lpstrReplaceWith,&pfr->wReplaceWithSz,&pfr->wReplaceWithLen);

      When you get that all done and compiled:
      Ctrl-I=TAB
      Ctrl-J=LF
      Ctrl-M=CR

       
    • pshute

      pshute - 2007-06-04

      To work with newlines I'd advise using the advanced search/replace (control+R) without regex turned on.  Control+M can be typed in either field to represent a newline combination (which could be LF, CR or CR+LF, depending on the file format).

      Look at http://notepad-plus.sourceforge.net/uk/newlineFindReplace-HOWTO.php for more details.

       
      • Nobody/Anonymous

        The flaw I seem to dealing with is that for the file I am working on each line ends with a CR LF, however do to problems with the source I also have several lines with just a LF.

        I want to remove the LF's but not the CR LF's, there appears to be no way to work with these tokens properly.  The sad thing is that notepad, yes generic old windows notepad actually functions the best regarding this problem but it can only handle a tenth of the file at a time without locking up.

        I find it extremely disappointing that no text editor out there seems to have better functionality then windows notepad.

         
    • pshute

      pshute - 2007-08-15

      If you're trying to make sure that every single line ends in CR LF, just use Format/Convert to Unix to change them all to LF, then Format/Convert to Windows to change them all back to CR LF.

      If you want to change just the LF's to something else, I'm not sure it can be done.  If you read http://notepad-plus.sourceforge.net/uk/newlineFindReplace-HOWTO.php, method 1.1 allows you to select the newline before commencing find/replace.  This pastes the newline into the search field.  I'll leave it to you to see if it works for LF.  If it does it'll likely find them in the CR LF's too.