-
Notifications
You must be signed in to change notification settings - Fork 24
Search_Replace
Jochen Staerk edited this page Dec 21, 2015
·
1 revision
Searching is demonstrated in Snippet 12, here is a sample how you can search and replace:
String keywords[] = {"SearchItem1", "SearchItem2"};
String keyvalues[] = {"ReplaceItem1", "ReplaceItem2"};
for (int keywordIndex = 0; keywordIndex < keywords.length; keywordIndex++) {
// replace all keywords by their respective keyValues
// noa does not seem to support replacements(XReplaceable), so lets initiate a search and replace the occurences individually
SearchDescriptor searchDescriptor = new SearchDescriptor(keywords[keywordIndex]);
searchDescriptor.setIsCaseSensitive(true);
ISearchResult searchResult = this.parentWizard.getDocument().getSearchService().findAll(searchDescriptor);
if(!searchResult.isEmpty()) {
//...and now select the result
ITextRange[] textRanges = searchResult.getTextRanges();
for (int resultIndex=0; resultIndex<textRanges.length; resultIndex++) {
textRanges[resultIndex].setText(keyvalues[keywordIndex]);
}
}
}