Menu

Making a macro using (find and) Replace

2008-03-14
2012-11-13
  • Nobody/Anonymous

    Hi there.

    I am a bit new to n++ but i already love it. However i am a bit tired of a small problem. In my company we use a german windows environment while some other software uses english digits. So it happens that 2.45345 != 2,45345 for example. When i copy the code in to Excel or similar i get the wrongt numbers.

    Till now i did everything by hand. Replacing all spaces to tab stops and "." to ",". But since i use n++ i tried to make a macro. However it seems that the "Replace" option isn't recogniced by the recorder and i am unable to save and run the macro. Is there any workaround or something i missed?

     
    • Nobody/Anonymous

      You could also take a look at the Simple Script Plug-In. It allows you to perform multiple actions with one script.

      >>Replace(string oldtext, string newtext): Replaces all instances of oldtext with newtext.

      Enclose oldtext and newtext in quotes.  For example, if you have:
      ________A bird lives in a tree.  Trees are green.
      and you run:
      ________Replace( "tree" , "house" )
      The new document would look like the following:
      ________A bird lives in a house.  houses are green.

       
    • Nobody/Anonymous

      Use a regular expression (regex) to do the trick.

      Press CTRL+F or CTRL+R to open the (advanced) Find/Replace dialog.

      Check the regular expressoin option.

      In the Find field, enter:
      (\d+)\.(\d)
      In the Replace field, enter:
      \1,\2

      Replace all occurrences, starting from the top of the document or using wrap mode.

      Notice that this will also change any "digits-dot-digits" sequence:
      \d______ searches for a digit
      +_______ searches for a continous string of the previous match pattern (digits)
      ()______ groups an expression so it can be referred to in the Replace field
      \.______ searches for a literal dot, simply . would match any character

      \1______ refers to the first () group, i.e. the integer value of the number
      \2______ refers to the second () group, i.e. the decimal part of the number

      Perhaps you can figure out how to do something similar for changing spaces into tab stops.

       
      • Nobody/Anonymous

        Correction: the decimal part may also exist of multiple digits.

        In the Find field, enter:
        (\d+)\.(\d+)