Home › Forums › General XMetaL Discussion › Makro Search Entity and Replace it › Reply To: Makro Search Entity and Replace it
Reply to: Makro Search Entity and Replace itJanuary 12, 2016 at 7:17 pm
I'm not sure why Selection.Find.Execute() wouldn't work here. I'd need more information to say why.
If it isn't working it could be that there is an issue with the version you are running. That API has had a disproportionate number of defects over the years, flip flopping back and forth between fully working and mostly working, primarily because of all the other APIs and document display functionality that interacts with it.
If you feel that a JScript regular expression would be best I think you would need to go to every element (unless you can limit that somehow), extract the text node portion of the content into a variable, run the regular expression on that, and if a match is found remove that portion of the text from the variable and put the text back into the document. That will be ugly. Alternatively, if the spaces are always at a specific location you might be able to use a Range to get to it (after finding it using JScript RegEx) by positioning the Range at the start or end of the element and counting a specific number of characters right or left. That will also be pretty ugly.
It might be better to concentrate on these things:
1) What problem is this causing? If it is causing an issue for another piece of software perhaps there is a way to adjust its behaviour. I would make this the priority if possible. There are many ways to handle spaces in XSLT for example (if this is a transformation issue).
2) How are the spaces getting into the documents? If it is through the XMetaL pretty printing feature then there are many ways to adjust that on an element by element basis or you can turn it off entirely. If something else is putting them in perhaps that can be adjusted as well.