How to remove space when combining variables in powershell?

Member

by dana , in category: Third Party Scripts , 5 months ago

How to remove space when combining variables in powershell?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , 5 months ago

@dana 

To remove space when combining variables in PowerShell, you can use the -join operator or the += operator to concatenate the variables without adding an extra space.


Here is an example using the -join operator:

1
2
3
4
$var1 = "Hello"
$var2 = "World"
$combined = $var1 + $var2
Write-Host $combined


In this example, $combined will contain "HelloWorld" without any space between the two variables.


Another example using the += operator:

1
2
3
4
5
6
$var1 = "Hello"
$var2 = "World"
$combined = $var1 + $var2
$combined = $var1
$combined += $var2
Write-Host $combined


In this example, $combined will also contain "HelloWorld" without any space between the two variables.

Related Threads:

How to remove the white space around a chart in chart.js?
How to remove leading white space inside xml file in php?
How to remove leading white space inside xml file in php?
How to remove all characters except alphabets and space in php?
How to rewrite a space (%20) in .htaccess?
How to split string by space in PHP?