Compare punctuation characters in two strings, create third string

What would be a good approach to set up a macro that detects the presence of the characters .,{}!? in one variable and matches them with equivalent characters (if present) in another variable?

That is:

Variable A: Garage sale!
Variable B: Garageverkoop?

Produces: Garageverkoop!

(for the trailing characters ,.! and ?)

Variable A: Calculate [W1].
Variable B: Bereken {W1}

Produces: Bereken [W1].

(for the surrounding characters {}, [] and ())

The best I can suggest would be something like this:

If Variable A contains [
    Search And Replace Variable B { with [
    Search And Replace Variable B ( with [
    Search And Replace Variable B } with ]
    Search And Replace Variable B ) with ]
If Variable A contains (
    Search And Replace Variable B { with (
    Search And Replace Variable B [ with (
    Search And Replace Variable B } with )
    Search And Replace Variable B ] with )
If Variable A contains {
    Search And Replace Variable B ( with {
    Search And Replace Variable B [ with {
    Search And Replace Variable B ) with }
    Search And Replace Variable B ] with }
If Variable A matches "[,]$"
    Search And Replace Variable B with regular expression [,.!?]*$ with ,
If Variable A matches "[.]$"
    Search And Replace Variable B with regular expression [,.!?]*$ with .
If Variable A matches "[!]$"
    Search And Replace Variable B with regular expression [,.!?]*$ with !
If Variable A matches "[?]$"
    Search And Replace Variable B with regular expression [,.!?]*$ with ?

Something like that anyway.

Thanks you, Peter. I’ll try to implement this :slight_smile: