Replace Space with Comma in PowerShell

💡 TL;DR

To replace space with comma in PowerShell, you can use String’s replace() method or PowerShell’s replace operator.

Here is simple example:

There are multiple ways to replace Space with Underscore in PowerShell. Let’s go through them.

Using String’s replace() method

Use string’s replace() method to replace space with comma in PowerShell.

Replace method returns new string and replaces each matching string with new string.
Replace methods takes two arguments:

  • substring to find in given string : space
  • replacement String for found substring: comma

Using replace operator

to replace space with comma in PowerShell, use PowerShell’s replace operator .

Replace operator takes two arguments:

  • substring to find in given string : space
  • replacement String for found String: comma

As you can see, replace operator replaced all spaces with comma in the String.

Please note that we have assigned result of replace() method or replace() operator to new string.

That’s all about how to replace space with comma in PowerShell.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *