Posts

Showing posts from September, 2009

Search and Replace in ODT using AODL

Recently I needed to create a way to search and replace a word in a OpenOffice OpenDocument ODT. It would seem the project itself already has a library AODL (take care, at least two other project pages but with older code) that exposes the format model but I didn't find any utility methods like search and replace functionality. I've created two versions of the method, one a old-style, imperative approach, and the other, a LINQ version. As I'm still new to LINQ it would seem that the classical approach produces a more efficient code. Anyone care to chip in and make a faster algorithm? In this particular version I'm just going for simple string equality, I didn't want to go with other StringComparison methods (just look at the Equals overload method). public static void SearchAndReplaceString(TextDocument document, string searchText, string replaceText) { var content = document.Content; foreach (var item in content)