Search and Replace
kray at sonsothunder.com
Tue Oct 15 21:14:01 CDT 2002
> On Wednesday, Oct 16, 2002, at 08:41 Australia/Sydney, Dan Friedman
> > Greetings!
> > 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.
> I feel a regex coming on. Are you there, Ken?
I'm here! :-) It's a little tricky (what with the capitalization and
everything), but here goes:
function replaceGender whatText
put "he,him,himself,his,he's,boy,guy" into SearchWordsMale
put "she,her,herself,her,she's,girl,gal" into SearchWordsFemale
set the wholeMatches to true
if it is true then
put char tStart to tEnd of tText into tFoundChunk
put (charToNum(toUpper(char 1 of tFoundChunk)) = charToNum(char 1 of
tFoundChunk) into isUpper
put itemOffset(tFoundChunk,SearchWordsMale) into tItem
if tItem <> 0 then
put item tItem of SearchWordsFemale into temp
if isUpper then put toUpper(char 1 of temp) into char 1 of temp
put temp into char tStart to tEnd of whatText
-- you decide... bail? error out? ignore?
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
More information about the use-livecode