Forum Discussion
dkrabo
Feb 07, 2022Copper Contributor
Masking Sentences
what is the best way to get the result of a** d** g** from input of 'abc def ghi'? with the least performance hit.
$test = 'abc def ghi'
((($test -split ' ')).substring(0,1) ) -join ' '
not sure how to add the ** or even a single * will be good. I need to do this to quite a big data, so I need it to run as fast as you can without using the | on each value...
dkrabo
Ok, created a file containing this to test on (d:\temp\x.txt in my case)abc def ghi
jkl mno pqr
stu vwx yzIf I let this script run on it:
foreach ($line in get-content d:\temp\x.txt) { (((($line -split ' ')).substring(0,1) ) -join ' ').Replace(' ','** ') | foreach {$_ + '**'} }
This is the output:
a** d** g**
j** m** p**
s** v** y**- Jonathan_AllenBrass Contributor
@dkrabo the solution from Harm_Veenstra seems pretty optimised, testing on a 10,000 line text file it masks all values in about 2s when part of a pipeline.
- Didn't even test it in that amount of data 🙂