PoshCode Archive  Artifact [5faee92d0e]

Artifact 5faee92d0e14ecc650f5a652c28a9157a610654fd6a8a201e5e7183e719ea8ea:

  • File Correction.ps1 — part of check-in [0690cc91b2] at 2018-06-10 13:23:13 on branch trunk — Dear scripters, (user: Klaus Schulte size: 991)

# encoding: ascii
# api: powershell
# title: Correction
# description: Dear scripters,
# version: 0.1
# type: function
# author: Klaus Schulte
# license: CC0
# function: Convert-ToCHexString
# x-poshcode-id: 3271
# x-archived: 2015-04-30T04:17:04
# x-published: 2012-03-10T04:21:00
#
# the original script won’t work, beacuse a “)” is missing in the param statement and the automatic $input variable is used as a parameter to the function but not in the Encoding.GetBytes method where an undefined parameter $str is encountered!
# I would prefer to just convert strings into char arrays and return the byte code as hex chars and wrap it into a small advanced function that returns the hex chars joined by a seperator like ‘,’
# Klaus (Schulte)
#
function Convert-ToCHexString {
[CmdletBinding()]
param (
    [Parameter(ValueFromPipeline=$true,Mandatory=$true)][string]$str
)    
   process { ($str.ToCharArray() | %{ "0x{0:X2}" -f [int]$_  }) -join ',' }
}