forked from gangstanthony/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFix-Spaces.ps1
37 lines (34 loc) · 1.04 KB
/
Fix-Spaces.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# EXAMPLE:
# $a = @(
# 'System File Checker Utility (Scan On Every Boot) = sfc /scanboot'
# 'System File Checker Utility (Return Scan Setting To Default) = sfc /revert'
# )
#
# PS C:\> Fix-Spaces '=' $a
# System File Checker Utility (Scan On Every Boot) = sfc /scanboot
# System File Checker Utility (Return Scan Setting To Default) = sfc /revert
function Fix-Spaces {
param (
[string]$delim = $(Throw 'A delimiter must be supplied.'),
[string[]]$array
)
$len = 0
$array | % {
if ($_.contains($delim) -and $_.indexof($delim) -gt $len) {
$len = $_.indexof($delim)
}
}
$array | % {
if ($_.Contains($delim)) {
$front = $_.substring(0, $_.indexof($delim))
$back = $_.substring($_.indexof($delim) + $delim.Length)
if ($front.length -lt $len) {
$spaces = $len - $front.Length - 1
0..$spaces | % {$front += ' '}
}
$front + $delim + $back
} else {
$_
}
}
}