Page 1 of 1

Search and replace

Posted: Wed Jun 10, 2009 12:41 pm
by Andycal
Hiya all,

I'm convinced (I might be very wrong though) that I've seen an example somewhere of a multiple search and replace thing. There was a text box with some content and another with some words like this:

white, black
red, green

And it would go through and replace all instances with the first words with the second.

Anyone seen this? I've been through loads of examples and I'm probably missing it somewhere.

Andy.

Posted: Wed Jun 10, 2009 1:30 pm
by Mark
Hi Andy,

I'm not sure what you're after. Perhaps this:

put replaceText(fld 1,"red","green") into fld 1

Best,

Mark

Posted: Wed Jun 10, 2009 1:35 pm
by Andycal
Hi Mark,

That's the gist of it, however the demo I saw allowed for multiple seach and replace, but while thinking about it, I think it's pretty easy anyway.

Correct me if I'm wrong, but I just do a 'for each tLine in fld 'Replacements' and then split on the comma, and replace the first word with the second word.

The whole idea is that I've got a big field of text with lots of abbreviations in it and I want to replace all the abbreviations. I've got another field with the abbreviation and the full word, comma seperated, each one on a seperate line.

You know what, it's difficult to explain, I should go and try it out!

Posted: Wed Jun 10, 2009 2:31 pm
by Mark
Andy,

I don't understand you! The replace function replaces all instances of a string. What else do you want?!

Mark

Posted: Wed Jun 10, 2009 3:02 pm
by Andycal
Told you it was confusing!

Let's say I've got the following paragraph:
"Outpt rose by 0.3% from the prev mnth the Off. for National Stats said. Analysts had been expecting outpt to fall by 0.1%

Mnf rose 0.2%, which was also an unexpected rise."
Now, in this, plus other documents the same abbreviations are used in the same way, so I want to turn the abbreviations into the full words. I have a list of the abbreviations and full words as a comma seperated file:

Outpt, Output
prev, previous
Off., Office
Stats, Statistics

So I have one text box with the paragraph in that contains a lot of abberviated words and I have another text box with the comma seperated list as above. I then press a button and it goes through all of them and replaces each occurance.

Does that make sense?

Posted: Wed Jun 10, 2009 3:21 pm
by Mark
Hi Andy,

What you want is this:

Code: Select all

put fld "Abbrevs" into myAbbrevs
replace comma & space with comma in myAbbrevs
lock screen
repeat for each line myAbbr in myAbbrevs
  replace item 1 of myAbbr with item 2 of myAbbr in fld "Paragraph"
end repeat
unlock screen
I believe this is almost the same as what you describe in your previous message.

Best,

Mark

Posted: Wed Jun 10, 2009 3:33 pm
by Andycal
I was just about to post this:

Code: Select all

on mouseUp
   set the columndelimiter to comma
   repeat for each line tLine in fld "fldSearch"
      put word one of tLine into tFind
      replace "," with "" in tFind
      put word two of tLine into tReplace
      replace tFind with tReplace in fld "fldText"
   end repeat
         answer "All done! " with "OK"
end mouseUp
Yours looks much more elegant!

I'll go try it...