[futurebasic] Re: [FB] MacinTalk

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 1999 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Sun, 14 Nov 1999 09:37:06 -0600

FluxerIIxi@... wrote:

> If i understand you correctly then I see what you mean, what I would do
> myself is make an FN checkText$ that would look for all of the offending
> strings. Like this...
>
> REM source doesn't really work
>
> _gOffendingStr = 50   REM how many strings we will search for
>
> LOCAL FN getNextOffendingString$ (current%)
>  SELECT current%
>   CASE 1
>     returnX$ = "neibor"
>   CASE 2
>     returnX$ = "Sean"
>  END SELECT
> END FN = returnX$
>
> LOCAL FN checkStr$ (theStr$)
>  FOR n = 1 to LEN(theStr$)
>   FOR id = 1 to _gOffendingStr
>    x$ = FN getNextOffendingString$ (id%)
>    LONG IF INSTR$(x$) REM something to see if it is in the current string
>     theStr = FN replaceStr (x$,n)   REM make an FN to replace something$ with
> x$ and pass it back
>    END IF
>   NEXT
>  NEXT
> END FN =theStr
>
> in english, ok,
> 1. I set a constant to how many strings that I want to check for
> 2. I send the string that I am checking for to my FN
> 3. the FN will FOR/NEXT for the LEN(of the string$)
> 4. then I will INSTR$ to look for the string
> 5. if the string is found, then I will send it to a replace string FN
> 6. that will look for the string and replace it with the correct one
> ex:
> LOCAL FN replaceStr (what$,offendingId)
>  SELECT offendingId
>    CASE 1
>      myReplace$ = "Nabor"
>    END SELECT
>   replace what$ with myReplace$
> END FN
>
> For me doing things modular is a big thing, so I would think this would be a
> good idea, if you can understand what i am getting at. That way to add more
> strings, all your will have to do is add 1 to the _constant and then add the
> find/replace to the SELECT x statement

Here's a simplification to that scheme:

Create two string arrays, one called "goodWords$", the other called
"badWords$".  They will each be DIMensioned to hold _gOffendingStr strings.
badWord$ holds all of the unpronouncable words you want to look for (like
"neighbor," etc.) and goodWord$ holds all of the phonetic equivalents (like
"nabor," etc.).  Make sure that the words in one array are in the "same order"
as the words in the other array, so that for example goodWord$(17) is the
phonetic equivalent of badWord$(17).

Having done this, you don't need those big SELECT CASE statements nor those two
auxiliary functions.  Your code might look something like this:

LOCAL FN checkStr$ (theStr$)
  FOR id = 1 to _gOffendingStr
    where = INSTR(theStr$, badString$(id), 1)
    LONG IF where > 0
      'Replace the bad string:
      theStr$ = LEFT$(theStr$, where-1) + goodString$(id) + MID$(theStr$,
where+LEN(badString$(id)))
    END IF
  NEXT
END FN = theStr$

Note that I removed your outer "FOR n" loop.  The INSTR function essentially
"walks through" the whole length of the string for you, so there is no need for
you to do that explicitly with a FOR loop.

Hope this helps.
- Rick