I'm looking to run through long string sentences in PowerShell and return a new line after every 32 characters + space (to avoid adding new lines in the middle of a word). Here's what I've tried thus far:
$Runonsentence = 'Interestingly, Bryan A. Garners "The Oxford Dictionary of American Usage and Style" states that while there is a distinction between run-on sentences and comma splices, it isnt typically noteworthy. However, Garner also adds "The distinction can be helpful in differentiating between the wholly unacceptable (true run-on sentences) and the usually-but-not-always unacceptable (comma splices).'
Filter Get-Stringy {
for($num = 0; $num -le $_.Length-32; $num+=32) {
$indexer = $_.Substring($num, 32)
$parser = $indexer.LastIndexOf(" ", 32)
$trimmer = $indexer.Split($parser)
$trimmer.Trim()
}
}
$Runonsentence | Get-Stringy
And here is what it returns:
Interestingly, Bryan A. Garners
"The Oxford Dictionary of Americ
an Usage and Style" states that
while there is a distinction bet
ween run-on sentences and comma
splices, it isnt typically notew
orthy. However, Garner also adds
"The distinction can be helpful
in differentiating between the
wholly unacceptable (true run-on
sentences) and the usually-but-
not-always unacceptable (comma s
As you can probably see from the results above, the words at the end are being cut-off and the entire string isn't being run through or displayed. If there is a different strategy or approach to doing so, it'd be much appreciated!

