Replace All Duplicates of Each Word with Underlines

Problem description & analysis

Below are a set of strings:

Here here here we go!

 

So they're finally here, performing for you

If you know the words, you can join in too

Put your hands together, if you want to clap

As we take you through this monkey rap!

We are trying to replace all duplicates of each word with underlines, as shown below:

Here ____ ____ we go!

 

So they're finally ____, performing for you

If ___ know the words, ___ can join in too

Put your hands together, __ ___ want to clap

As __ take ___ through this monkey rap!

Solution

Write the following script p1.dfx in esProc:

A

1

=str.words@w()

2

>A1.run(if(asc(left(lower(~),1))>=97   &&     asc(left(lower(~),1))<=122,if(words.pos(lower(~)),~=fill("_",len(~)),words|=lower(~))))

3

=A1.concat()

Explanation:

Set two script parameters:

1. Parameter str represents the current string.

2. Parameter words is an empty set.

A1 @w option enables extracting all characters from string str; and extracting English letters as a word.

A2 Loop through each row of A1’s table sequence, during which a member is an English word if the lowercase of the first letter is any among a-z, check whether the lowercase word is included in parameter words, replace it with an underline of equal length if it is, or append the lowercase word to parameter words if it isn’t.

A3 Concatenate results of loop through A1’s table sequence into a string.

Q & A Collection

https://stackoverflow.com/questions/59309109/how-could-we-replace-repeated-words-by-underscores-java