Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Deleting text from a note using Agent
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1208585514

Message started by Gordon Ferrier on Apr 19th, 2008, 2:11am

Title: Deleting text from a note using Agent
Post by Gordon Ferrier on Apr 19th, 2008, 2:11am

I have a few hundred notes, each containing a quotation. Most of the quotations end with the same string of characters: a space followed by a "~" (tilde) then the name of the person who originated the quotation. These were imported from a single Word document into individual notes. I have created an Agent to extract the name of the author of the quote into an Author attribute, which worked successfully. I now want to delete this redundant text from the end of the note i.e. delete from the space character preceding the tilde through to the end of the note. I can capture this text using Agent logic in a regexp and backreferencing, thus:

Text(( ~.+))

This places the offending text into $1. What I then thought would be straightforward to do is Text=$Text-$1: however when I do that I end up with the redundant text appended to the end of the note, and that, of course, repeats each time the Agent runs.

I'm clearly doing something wrong, but what?


Title: Re: Deleting text from a note using Agent
Post by DerikBadman on Apr 19th, 2008, 9:01am

Perhaps you'd want to capture the text you want to keep and then replace the Text attribute with that instead of capturing the text you don't want and trying to delete it. Make sense?

Title: Re: Deleting text from a note using Agent
Post by Gordon Ferrier on Apr 20th, 2008, 4:09am

DerikBadman's suggestion is an interesting example of thinking laterally, and certainly worth trying - thanks. I'd still like to know why my proposed "solution" doesn't work, however, if anyone can suggest a reason.

Title: Re: Deleting text from a note using Agent
Post by Mark Bernstein on Apr 21st, 2008, 1:02pm

Gordon Ferrier's proposed action

    Text=$Text-$1

doesn't work, because substraction isn't defined for strings.  Addition is defined, as concatenation: "cats"+"!" is "cats!".  But substraction is not defined.

Historically, the '+' operator for concatenation is used in quite a few popular computer languages; C++, Smalltalk, awk, and perl all share this, if I remember right.  

I've never seen '-' as "substring deletion", but I see no objection to it.  If the substring to be deleted occurs more than once, which occurence(s) should be deleted?

Title: Re: Deleting text from a note using Agent
Post by Gordon Ferrier on Apr 26th, 2008, 3:29am

Mark B pointed out that "-" is not supported as a string deletion operator, which certainly explains why my proposed "solution" didn't work. In fact I followed DB's suggestion and found the text I wanted to keep, and then replaced the whole of the note text with that. Intuitively, however, I think there may be occasions where deletion is the only option, although Mark's question about what to do when there is more than one occurrence of the search string is a good one. Logically the regexp ought to find the first (and probably longest) string that matches search string and that could be marked using back referencing. But then would the regexp engine stop at that point or continue trying to find more matches?

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.