swapna
swapna

Reputation: 143

Notepad++ replacing a series of characters with numbers

I have a document in which I have to replace some special characters with numbers in ascending order. I have marked those characters as "&&", I have to replace first 14 && with 1, next 14 && with 2, next 14 && with 3 and so on....next 14 && with 250. Is there a better and fast way to do it. Thanks..

Upvotes: 0

Views: 2239

Answers (2)

psxls
psxls

Reputation: 6925

The only way I can think of accomplishing your task in Notepad++, is with the use of Python Script plugin.

  1. Install Python Script plugin, from Plugin Manager or from the official website.
  2. Then go to Plugins > Python Script > New Script. Choose a filename for your new file (eg replace_series.py) and copy the code that follows.
  3. Run Plugins > Python Script > Scripts > replace_series.py and a new tab will show up the desired result.
number = 1
content = editor.getText()
while "&&" in content:
    content = content.replace("&&", str(number), 14)
    number += 1

notepad.new()
editor.addText(content)

Upvotes: 3

sala
sala

Reputation: 181

you can try this in java, it's not very nice, but it should work

private void readAndWrite() {
    String [] lines = new String[1000];
    try {
        int n=0;
        BufferedReader br = new BufferedReader(new FileReader("d:/test.txt"));


        while (br.readLine()!=null) {
            lines[n]=br.readLine();
            n++;                
        }

        FileWriter fw = new FileWriter("d:/test2.txt");
        BufferedWriter bw = new BufferedWriter(fw);
        int num =1;
        int count=1;
        String test="";
        int p=0;
        while (lines[p]!= null) {
             bw.write( lines[p].replace("&&", Integer.toString(num))+"\n");
             bw.newLine();
             bw.flush();
            count++;
            p++;
            if (count==15) {
                count=1;
                num++;
            }

        }
        fw.close();


    }catch (NullPointerException e) {

    } 
    catch (FileNotFoundException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }

Upvotes: 1

Related Questions