LoginSignup
0
1

More than 5 years have passed since last update.

決まった文字数で折り返す

Posted at

メモです。

久しぶりに while とか index を使った。最近はコマンドに頼りすぎで脳が頼りない。

Function Fold-String {
    param(
        [Parameter(Mandatory=$False)]
        [int]$Width = 80,

        [Parameter(ValueFromPipeline=$True)]
        [string[]]$String
    )
    process {
        foreach($s in $string){
            $index = 0
            $Length = $s.Length
            while(($index + $Width) -lt $Length){
                $s.SubString($index, $Width) # output
                $index += $width
            }
            $s.SubString($index) # all of remaining
        }
    }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1