Powershell – Remove space between two variables


I have two array’s which contain a selection of strings with information taken from a text file. I then use a For Loop to loop through both arrays and print out the strings together, which happen to create a folder destination and file name.

The above takes a text file, splits it into separate parts, stores some into the locationArray and other information in the imageArray, like this:

locationArray[0] would be L:\Place\

imageArray[0] would be SERVERNAME_C_VOL_b001_i005.spi

Then I run a For Loop:

But it places a space between the L:\Place\ and the SERVERNAME_C_VOL_b001_i005.spi

So it becomes: L:\Place\ SERVERNAME_C_VOL_b001_i005.spi

Instead, it should be: L:\Place\SERVERNAME_C_VOL_b001_i005.spi

How can I fix it?


Option #1 – for best readability:

Option #2 – slightly confusing, less readable:

Option #3 – more readable than #2, but more lines:


Powershell – Remove space between two variables by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply