Masking Sentences

Occasional Visitor

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...

4 Replies

@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 yz

 

If 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**

@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 :)
well, as you had answered the question there wasnt much else for me to do ! :)