Common/Public/Get-StringSection.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function Get-StringSection
{
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [string]$String,

        [Parameter(Mandatory)]
        [int]$SectionSize
    )

    process
    {
        0..($String.Length - 1) | 
            Group-Object -Property { [System.Math]::Truncate($_ / $SectionSize) } |
            ForEach-Object { -join $String[$_.Group] }
    }
}