Search and Replace
Dan Friedman
dan at clearvisiontech.com
Tue Oct 15 22:15:01 EDT 2002
Ken,
I can't get [your] function to work. It never exits out of the repeat.
Although the matchChunk does return true, the tStart and tEnd variables are
never being filled with anything. What am I doing wrong?
(Please excuse my ignorance in regards to the matchChunk call.. I've read
the docs about a zillion times and I still don't get matchChunk and
matchText)
Thanks!
-Dan
> I'm here! :-) It's a little tricky (what with the capitalization and
> everything), but here goes:
>
> function replaceGender whatText
> local tStart,tEnd
> 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
> repeat forever
> get
> matchChunk(whatText,"[^A-Za-z0-9](boy|h(e|im|is|imself|e's)|guy)[^A-Za-z0-9]
> ",tStart,tEnd)
> 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
> else
> -- you decide... bail? error out? ignore?
> end if
> else
> exit repeat
> end if
> end repeat
> return whatText
> end replaceGender
More information about the use-livecode
mailing list