CmdID / PowerShell / Cmdlets / Convert
Convert-String
Formats a string to match examples. PowerShell reference
From the PowerShell reference 2 parameters
What it does
Formats a string to match examples. The cmdlet formats a string to match the format of examples.
Convert-String [-Example <System.Collections.Generic.List1[System.Management.Automation.PSObject]>] -InputObject <String> [<CommonParameters>]
Convert format of a string
"Mu Han", "Jim Hance", "David Ahs", "Kim Akers" | Convert-String -Example "Ed Wilson=Wilson, E."IdentifySimplify format of a string
$composers = @("Johann Sebastian Bach", "Wolfgang Amadeus Mozart", "Frederic Francois Chopin", "Johannes Brahms")
$composers | Convert-String -Example "first middle last=last, first"IdentifyOutput management when strings don't match example
$composers = @("Johann Sebastian Bach", "Wolfgang Amadeus Mozart", "Frederic Francois Chopin", "Johannes Brahms")
$composers | Convert-String -Example "first middle last=middle, first"IdentifyCaution with beauty spaces
$composers = @("Antonio Vivaldi", "Richard Wagner ", "Franz Schubert", "Johannes Brahms ")
$composers | Convert-String -Example "Patti Fuller = Fuller, P."IdentifyFormat process information with multiple patterns
$ExamplePatterns = @(
@{before='"Hello","World"'; after='World: Hello'},
@{before='"Hello","1"'; after='1: Hello'},
@{before='"Hello-World","22"'; after='22: Hello-World'},
@{before='"hello world","333"'; after='333: hello world'}
)
$Processes = Get-Process | Select-Object -Property ProcessName, Id | ConvertTo-Csv -NoTypeInformation
$Processes | Convert-String -Example $ExamplePatternsIdentifyIts page in the reference: Convert-String.
Parameters
-ExampleSpecifies a list of examples of the target format. Specify pairs separated by the equal sign (=), with the source pattern on the left and the target pattern on the right, as in the following examples:
- -Example "Hello World=World, Hello"
- -Example "Hello World=World: Hello",'"Hello","1"=1: Hello'
NOTE: The second example uses a list of patterns
Alternatively, specify a list of hash tables that contain Before and After properties.
- -Example @{before='"Hello","World"'; after='World: Hello'}, @{before='"Hello","1"'; after='1: Hello'}
CAUTION: Avoid using spaces around the equal sign(=), as they are treated as part of the pattern.-InputObjectSpecifies a string to format.