PDA

View Full Version : Solved: Find all ' in all word inserted in curly bracket



Pasquale
09-03-2005, 05:02 AM
Hallo I need yet help.
I have a long doc with words at the begin of phrase and others inserted in curly bracket.
I must repalce all ' (apostrophes) of the words inserted in curly Bracket when it is follow by a space with ' (apostrophes) without space.
Sample:
Gen 1:9 Dio disse: Siano raccolte in un sol luogo le acque che sono sotto il cielo e appaia l' asciutto. E cos? avvenne.{1,9 ieri sera l' origine della storia l' oriente other word d' ordine, c' era ecc.}.

replace with:
Gen 1:9 Dio disse: Siano raccolte in un sol luogo le acque che sono sotto il cielo e appaia l' asciutto. E cos? avvenne.{1,9 ieri sera l'origine della storia l'oriente other word d'ordine, c'era, ecc.}.
:( :( :( :dunno :dunno

(Hi Tony - I have effort to solve it by is very difficult for me.

Pasquale :hi:

TonyJollans
09-04-2005, 05:55 AM
Hi Pasquale,

I don't think this one can be done with a single Find and Replace :)

But this:

Find what: \{(*)' (*)\}
Replace with: {\1'\2}
Use wildcards: checked

Will replace a single occurrence of (apostrophe space) with (apostrophe).

You could manually do Replace All until you get a message telling you that zero replacements were made - or you could record doing it once and make a loop by changing the Execute to something like:

While Selection.Find.Execute(Replace:=wdReplaceAll):Wend

Pasquale
09-04-2005, 09:39 AM
Hi Tony,
The find and replace, select also the text not inserted in curly bracket. It select large parts of text inserted and not inserted in curly bracket. The doc is very long and alternate parts inserted in curly bracket and not inserted in curly bracket.
Thanks pasquale

TonyJollans
09-04-2005, 10:12 AM
Sorry, Pasquale.

I just did a quick test on your posted sample and, of course, it worked but I didn't think about what would happen when you had lots of the stuff in a single document.

I'm away for the rest of the day - I'll think about how best to do it and come back tomorrow. The two-character combination is a bit of a problem.

One way, perhaps, would be to change ALL (apost space) to some otherwise unused character, say ? for this example, - then search for (\{[!\}?]{1,})?([!\{\}]{1,}\}) and replace all with \1'\2 till there are no more (with the loop) - then replace all ? with (apost space) again - to set back the ones outside braces.

TonyJollans
09-04-2005, 08:38 PM
Hi Pasquale,

I think the way I outlined is as good as any - here's some code which should do it:

Selection.HomeKey wdStory

With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

.Text = "' "
.Replacement.Text = "?"
.Execute Replace:=wdReplaceAll

.Text = "(\{[!\}?]{1,})?([!\{\}]{1,}\})"
.Replacement.Text = "\1'\2"
While .Execute(Replace:=wdReplaceAll): Wend

.Text = "?"
.Replacement.Text = "' "
.Execute Replace:=wdReplaceAll
End With


In the unlikely event of you having any ? characters in your document already, then replace it with some other character (which isn't in your document) everywhere it's used (three places).

Pasquale
09-05-2005, 12:16 AM
Hi tony,
it doesn't works in all words inserted in curly bracket, but only in a few pieces of text inserted in curly bracket, i post a file.
Thanks
pasquale

TonyJollans
09-05-2005, 02:26 AM
Hi Pasquale,

Well, there's something I've learnt today - and before breakfast.

This looks like it is going to require more complex code than it really should. I will post back later.

TonyJollans
09-05-2005, 07:20 AM
Hi Pasquale,

Want to try this one?

Selection.HomeKey wdStory

With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
End With

Do
Selection.Collapse wdCollapseEnd

With Selection.Find
.Text = "\{*\}"
.Replacement.Text = ""
.MatchWildcards = True
If Not .Execute Then Exit Do

.Text = "' "
.Replacement.Text = "'"
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With

Loop

What did I learn? That the construct {1,} which means "one or more occurrences of the preceding element" actually means from 1 to 255 occurrences. The joys of Word!

Pasquale
09-05-2005, 08:57 AM
Hi tony, it works very very well. I test yet.

pasquale

TonyJollans
09-05-2005, 09:27 AM
Excellent!