Replace All Duplicates of Each Word with Underlines #eg55
Judy
Posted on October 11, 2024
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:
Set two script parameters:
Parameter str represents the current string.
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.
Posted on October 11, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.