Search and Replace EVERY 2nd occurrence i.e. alternate occurrences
Submitted by Thursday, 3 February, 2011 - 10:45
on
Hi, I'd like to be able to search and replace paragraph marks (\n) with tab marks (\t) for every other line down to the end of a document, effectively merging two lines into one with a tab in between.
thus turning
term1
term2
something else 1
something else 2
into
term1[tab]term2
something else 1[tab]something else 2
this is the code I have so far
SearchAndReplace.setSearchString("\\n");
SearchAndReplace.setReplaceString("\\t");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(true);
SearchAndReplace.setRegexp(true);
SearchAndReplace.replace(view);
SearchAndReplace.setSearchString("\\n");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(true);
SearchAndReplace.setRegexp(true);
SearchAndReplace.find(view);
but if I put it into a loop for textarea number of lines, it replaces ALL occurrences of \n and not every other one.... I'm stumped.
Anyone have any ideas please?
thus turning
term1
term2
something else 1
something else 2
into
term1[tab]term2
something else 1[tab]something else 2
this is the code I have so far
SearchAndReplace.setSearchString("\\n");
SearchAndReplace.setReplaceString("\\t");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(true);
SearchAndReplace.setRegexp(true);
SearchAndReplace.replace(view);
SearchAndReplace.setSearchString("\\n");
SearchAndReplace.setBeanShellReplace(false);
SearchAndReplace.setIgnoreCase(true);
SearchAndReplace.setRegexp(true);
SearchAndReplace.find(view);
but if I put it into a loop for textarea number of lines, it replaces ALL occurrences of \n and not every other one.... I'm stumped.
Anyone have any ideas please?