Search and Replace

Dan Friedman dan at
Tue Oct 15 17:58:02 EDT 2002


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 because

Replace "HE" with "SHE" in someText

Would turn "HELP" into "SHELP"

I've written this function about a dozen times and it still isn't working
perfectly.  Here's what I have to date:


function searchAndReplaceMaleToFemale TextToSearchNReplace
  set the caseSensitive to true
  set the itemDel to ","
  put "He,he,him,Him,himself,HimSelf,his,His,boy,Boy,he's,He's" into
  put "She,she,her,Her,herself,Herself,her,Her,girl,Girl,she's,She's" into
  put TextToSearchNReplace into TextToSearchNReplace2
  put quote&"!?,.:;[]{}()£$¢%^&¾„÷<>=+-Š³Œ²¡#ƒ§¶*€ªº\/" into tList
  repeat for each char tChar in tList
    replace tChar with space in TextToSearchNReplace2
  end repeat
  repeat with i = the number of words in TextToSearchNReplace2 down to 1
    if word i of TextToSearchNReplace2 is among the items of SearchWordsMale
      replace (word i of TextToSearchNReplace2) with (item (itemOffset(word
i of TextToSearchNReplace2,SearchWordsMale)) of SearchWordsFemale) in word i
of TextToSearchNReplace
    end if
  end repeat
  set the caseSensitive to false
  return TextToSearchNReplace
end searchAndReplaceMaleToFemale


Anyone got any ideas?

Thank you in advance,

If you feel like taking a stab at it... Here's some text to test with:

     The Reading goals for Becky are building comprehension using specific
strategies of [ answering questions, summarizing, and describing (beginning,
middle, end)].  He will be able to use phonics to decode words, show an
increasing his vocabulary, and gain fluency in oral reading. Becky will
strive to be able to read at grade level or above by the end of the year.
     The Mathematics goals for Becky is to know the addition/subtraction
facts, be able to solve word problems, gain a deeper understanding of place
value, and demonstrate a basic understanding of time and money.
     The writing goal for Becky is to write a paragraph using clear and
coherent sentences. Correct use of grammar, capitalization, and punctuation
should increase as the year progresses for him.
        Personal  Goals for Becky are to stay focused and on task  to
complete his work without  adult supervision.   Becky needs to make more
productive use of class time.  He is easily distracted and is often unable
to finish his assignments in class.  I am confident, with practice, Becky
will learn how to use his time wisely.        

More information about the use-livecode mailing list