Recoding: search and replace

Mike Bonner bonnmike at gmail.com
Wed Nov 16 10:21:26 EST 2016


The only thing I would do different would be to use the "repeat for each"
form rather than putting into lines.  If your script is really long, the
time savings will add up.  I THINK it will make an even greater difference
because you a) have to look at a specific line, then b) you have to grab
the specific line, and then c) you have to put the modified line back in to
a specific line.  Even if the "if" doesn't fire for a line, it will still
have to count through from 1 to the line in question for every loop,
getting slower as it goes. (Plus the slowdown of doing it in a field rather
than a variable)

I think I would change it to this:

put the script of img "xxx" into tScript
repeat for each line tLine in tScript
switch -- for this particular thing, I find switch easier but if can be
made to work
   case tLine contains "unicodeText"
      put replacetext(tline,"unicodeT","t") & cr after tNewScript
      break
   case not (tLine contains "useUnicode")
      put tLine & cr after tNewScript
      break
end switch
end repeat
delete the last char of tNewScript
set the script of img "xxx" to tNewScript
if the result is not empty then answer error "There was a problem: " & the
result

On Wed, Nov 16, 2016 at 5:13 AM, Richmond <richmondmathewson at gmail.com>
wrote:

> So; here I am, as per usual, replying to my own message having found that
> nothing quite so elaborate was required:
>
> /put empty into fld "fSSS1"//
> //   put the script of img "xxx" into fld "fSSS1"//
> //   put the number of lines of fld "fSSS1" into TERMINUS//
> //   put 1 into QOUNT//
> //   repeat until QOUNT > TERMINUS//
> //      if line QOUNT of fld "fSSS1" contains "unicodeText" then//
> //         put line QOUNT of fld "fSSS1" into PROCESST//
> //         put replaceText(PROCESST,"unicodeT","t") into line QOUNT of
> fld "fSSS1"//
> //      end if//
> //      if line QOUNT of fld "fSSS1" contains "useUnicode" then//
> //         put "--deprecated code removed (useUnicode)" into line QOUNT of
> fld "fSSS1"//
> //         end if//
> //         add 1 to QOUNT//
> //      end repeat//
> ///
> Richmond.
>
> On 6.11.2016 14:44, Richmond wrote:
>
>> I wonder if there is a way to replace this:
>>
>> set the unicodeText of fld "fDECODE" to (numToCodePoint(107) &
>> numToCodePoint(104))
>>
>> with this:
>>
>> *put (numToCodePoint(107) & numToCodePoint(104)) into fld "fDECODE"*
>>
>> where /(numToCodePoint(107) & numToCodePoint(104))/ vary?
>>
>> I have no great urge to do that sort of thing manually about 6 million
>> times.
>>
>> Richmond.
>>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the Use-livecode mailing list