Search and Replace
kee at kagi.com
Tue Oct 15 19:06:10 CDT 2002
On Tuesday, Oct 15, 2002, at 15:41 US/Pacific, Dan Friedman wrote:
> I need to switch the gender of some text. But, I'm having a hard time
> figuring out a way to do it. Obviously I can't do a simple replace
> Replace "HE" with "SHE" in someText
> Would turn "HELP" into "SHELP"
The way I would do it is to find all instances of "he" and see if the
character before it is an alpha and if the character after it is an
alpha. Take into consideration that "H" might be the 1st char (no char
alpha or otherwise preceding it) and/or "E" might be the last char (no
additional chars following it). If the char before is not an alpha and
the char after is not an alpha, then I'd do the swap.
If this is just one set of text, it should be pretty easy. If it is a
gazillion cards with data stored on them, put the target words on the
first card, go next card, then use find to locate a target card with a
target word. Then crawl through that text to do the analysis and swaps.
When you end up at the first card (since you will find the target word
there) delete the target word and repeat with the next one.
I didn't look at your set of swap words but you might want to put them
in such an order that this algorithm doesn't do strange things with
words that have just been swapped in.
More information about the use-livecode