Ordered Pair Deletion
Posted: 2024-07-30 06:48:29
G'day, all
I thought I would try to devise a Macro for the task described, but I confess I was defeated by the Macro Language. For example, I could determine whether or not a target string was found in the text, but I only ended up with a boolean value: I couldn’t even see how to select the found text or make use of it in further operations. So some guidance would be much appreciated.
I have several paragraphs (not necessarily contiguous) of the following form:–
initial_string {{"stringX1", "stringY1"}, {"stringX2", "stringY2"}, {"stringX3", "stringY3"}}
So I basically have sets of ordered pairs.
The string designations here have no significance: the strings in the actual document could consist of any, and any number of, characters. Furthermore, the set in any given paragraph could contain any number of ordered pairs — not necessarily three as shown above. By way of concrete example, each ordered pair might represent the author and title of a book, and the book sought might be leaving my library in the (probably futile) hope that the light of erudition it represents illuminates some hitherto unenlightened corner of the universe. You get the idea….
I also have a target string.
I want to search a given paragraph of the above form for the target string. I don’t want to search all such paragraphs. I might want to search just the third one, for example. And I want to be able to set this in advance in the Macro (ie, I don’t need a dialog box to get input).
More specifically, I want to search the nominated paragraph to see if the target string is contained in the second string of any of the ordered pairs. If it is, I want to delete that entire ordered pair from the set, while leaving the rest of the paragraph unchanged. The target string will appear at most once in the nominated paragraph.
Ideally, the Macro would work for ordered n-tuples, for any n ≥2, not just ordered pairs. And not necessarily looking at the second (or last) element of an n-tuple. (But I realize I’m being greedy here.)
Depending on where (if at all) the deletion occurs, some tidying up of the ordered pair separators (viz, “, ”) may be required, but I can handle this myself. As for the rest….
Cheers,
Adrian
I thought I would try to devise a Macro for the task described, but I confess I was defeated by the Macro Language. For example, I could determine whether or not a target string was found in the text, but I only ended up with a boolean value: I couldn’t even see how to select the found text or make use of it in further operations. So some guidance would be much appreciated.
I have several paragraphs (not necessarily contiguous) of the following form:–
initial_string {{"stringX1", "stringY1"}, {"stringX2", "stringY2"}, {"stringX3", "stringY3"}}
So I basically have sets of ordered pairs.
The string designations here have no significance: the strings in the actual document could consist of any, and any number of, characters. Furthermore, the set in any given paragraph could contain any number of ordered pairs — not necessarily three as shown above. By way of concrete example, each ordered pair might represent the author and title of a book, and the book sought might be leaving my library in the (probably futile) hope that the light of erudition it represents illuminates some hitherto unenlightened corner of the universe. You get the idea….
I also have a target string.
I want to search a given paragraph of the above form for the target string. I don’t want to search all such paragraphs. I might want to search just the third one, for example. And I want to be able to set this in advance in the Macro (ie, I don’t need a dialog box to get input).
More specifically, I want to search the nominated paragraph to see if the target string is contained in the second string of any of the ordered pairs. If it is, I want to delete that entire ordered pair from the set, while leaving the rest of the paragraph unchanged. The target string will appear at most once in the nominated paragraph.
Ideally, the Macro would work for ordered n-tuples, for any n ≥2, not just ordered pairs. And not necessarily looking at the second (or last) element of an n-tuple. (But I realize I’m being greedy here.)
Depending on where (if at all) the deletion occurs, some tidying up of the ordered pair separators (viz, “, ”) may be required, but I can handle this myself. As for the rest….
Cheers,
Adrian