Replace string in powershell array

Adeel ASIF picture Adeel ASIF · Aug 6, 2015 · Viewed 17.8k times · Source

This is my array :

$array who contains theses values :

Y:\155150716070\00000027.JPG
Y:\155150716070\00000028.JPG
Y:\155150716070\00000029.JPG
Y:\155150716070\00000030.JPG
Y:\155150716070\00000031.JPG
Y:\155150716070\00000032.JPG
Y:\155150716070\00000033.JPG
Y:\155150716070\00000034.JPG
Y:\155150716070\00000035.JPG
Y:\155150716070\00000036.JPG

How can i replace "JPG" by "TIF" to get something like that ?

Y:\155150716070\00000027.TIF
Y:\155150716070\00000028.TIF
Y:\155150716070\00000029.TIF
Y:\155150716070\00000030.TIF
Y:\155150716070\00000031.TIF
Y:\155150716070\00000032.TIF
Y:\155150716070\00000033.TIF
Y:\155150716070\00000034.TIF
Y:\155150716070\00000035.TIF
Y:\155150716070\00000036.TIF

Thanks for your help

Answer

mjolinor picture mjolinor · Aug 6, 2015

Using -replace as an array operator:

$array -replace 'JPG$','TIF'