Repeated placement of carriage return and line feed characters after a specified number of characters

P F
2014-06-05
2014-06-05
  • P F
    P F
    2014-06-05

    Trying to accomplish through NP++ on a Windows 7 (64 bit) operating system a means by which carriage return and line feed characters are placed after every nth character in a string of characters for readability purposes, similar to what the crlf.exe (32 bit) Windows executable program performed on Windows XP. For example, there is a random string of data which total 1500 characters and carriage return/line feed characters need to be placed after every 50 characters of data. The result would be 300 lines containing 50 characters each, followed by a carriage return/line feed at the end of each line.

     
  • THEVENOT Guy
    THEVENOT Guy
    2014-06-05

    Hello P F,

    No problem :-) It can be accomplished with a simple Search/Replacement in regular expression mode !

    One condition : the version of your N++ must be equal or higher to 6.00

    So :

    • Open the Replace dialog ( CTRL + H )

    • Check the Regular expression radio button

    • Check the Wrap around option, if necessary

    • Type in the Find what and Replace with zones, the regexes below :

    SEARCH : .{50}

    REPLACE : $0\r\n

    • Click on the Replace All button

    Et voilà !

    To sum up :

    • The Search part try to match fifty standard characters ( The DOT symbol represents any character different from \r, \n and \f )

    • The Replacement part re-write ALL the matched characters ( $0), followed with the usual Windows EOL ( \r\n ). Of course, if your file is an UNIX file, just write $0\n as replacement part !

    The use of the Python plugin could also split your text, quite easily !

    Enjoy our loved editor !

    Best Regards,

    guy038

    P.S. :

    You'll find good documentation, about the new Boost C++ Regex library ( similar to the PERL Regular Common Expressions ) used by N++, since the 6.0 version, at the TWO addresses below :

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

    The FIRST link explains the syntax, of regular expressions, in the SEARCH part

    The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part

     
    Last edit: THEVENOT Guy 2014-06-05