Brother Gabriel-Marie | 1 Jun 2010 22:34
Gravatar

Improved find/replace script

Hello (Sheri!)  Some time ago Sheri, you helped me with a find and
replace script.  This is one I made from your script to use on
highlighted text; this works, but I in my find-and-replace text file I
have to give the words both in sentence case as well as lowercase or it
won't find any words with the first letter capitalized.  How can I make
this script know whether to apply sentence case, uppercase or lower case
to the words?  Somehow it needs to know the case of the word it
imports.  But this script uses vectors and a general replacement
function and I can't figure out how to get ahold of a single incoming
word in order to change or compare it.  I just want to have lower-case
words in my find-replace list and then to fix the case as I replace the
words.  I am sure this sounds rather confusing!  Thank you!

Function ReplaceText(chgfile)
    . <at> CapCB()
    clip.copy    ;;copy selection
    wait.for(50)
    local thestring = clip.get    ;;get clipboard
    local chgread=file.readall(chgfile)
    local chgpat=regex.pcrecompile(?"(?m)^([^;][^=\r\n]*)=(.+)$")
    local chgcount=chgpat.pcrematchcount(chgread)
    if (chgcount==0) do
        messagebox("no change records found, quitting")
        quit
    else
        local chgVec=vec.create2D(chgcount, 3)
        chgpat.pcrematchall(chgread,"",chgvec)
        for (local i=0;i<chgcount;i++)
            thestring = replacechars(thestring,chgVec[i,1],chgVec[i,2])
        endfor
(Continue reading)

Sheri | 3 Jun 2010 18:22
Picon

Re: Improved find/replace script

Hi BGM,

Although you could certainly come up with a way to go one by one, i.e.: find a string-regardless-of-case,
determine its text case, replace-string-with-matching-case, I doubt it would be as quick as just making
global replacements in each possible case treatment.

e.g.:

thestring = replacechars(thestring,chgVec[i,1],chgVec[i,2])
thestring = replacechars(thestring,case(chgVec[i,1],"sentence"),case(chgVec[i,2],"sentence"))
thestring = replacechars(thestring,case(chgVec[i,1],"upper"),case(chgVec[i,2],"upper"))

Does that take care of it?

Regards,
Sheri

------------------------------------

PowerPro can be found here: http://www.ppro.org/
and here: http://ppro.pcrei.com/Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/powerpro-beginners/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/powerpro-beginners/join
(Continue reading)


Gmane