Reputation: 143
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
Reputation: 6925
The only way I can think of accomplishing your task in Notepad++, is with the use of Python Script plugin.
number = 1
content = editor.getText()
while "&&" in content:
content = content.replace("&&", str(number), 14)
number += 1
notepad.new()
editor.addText(content)
Upvotes: 3
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