PowerShell - Remove Last Comma From Output

Bobby Llih
Bobby Llih used Ask the Experts™
on
Can someone help, this function will convert strings of text to uppercase and add, "0x##," every two spaces.
However, there is an un-needed comma at the end. How do I remove end comma?
Function Convert_To_Hex ($Hex_01)
{
  $Hex = $Hex_01.ToUpper() -Replace '(..)', '0x$1, '
  Write-Host $Hex
}

Convert_To_Hex 87ceeb

# Output: 0x87, 0xCE, 0xEB,

Open in new window


Thanks In Advanced.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Function Convert_To_Hex ($Hex_01)
{
  $Hex = $Hex_01.ToUpper() -Replace '(..)', '0x$1, '
  $Hex = $Hex.substring(0,$Hex.length -2)
  
  Write-Host $Hex
}

Convert_To_Hex 87ceeb

# Output: x87, 0xCE, 0xEB

Open in new window

Author

Commented:
Many Thanks :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial