powershell - PowerShell中的特定bash命令(折叠-w1)?

标签 powershell fold

有人可以帮助我如何使用此bash过滤器:在powershell中折叠-w1吗?所以我需要在新行中写一个字符串的字符。 “例子blabla”
Ë
X
一种

p

Ë

b

一种
b

一种

最佳答案

另外一个选项:

$string = "example blabla"
$string -replace '(.)', "`$1`n"

您也可以这样替换:
$string -replace '', "`n"

但是这样,输出将具有换行符。

通过将替换内容包装在这样的函数中:
function Fold {
  param(
    [CmdletBinding()]

    [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
    [string]$String,

    [Parameter()]
    [alias('w')]
    $Width=80
  )

  $String -replace "(.{$Width})", "`$1`n"
}

您可以(或多或少)以与shell实用程序相同的方式使用它:
PS C:\> Fold -w:1 'example blabla'
e
x
a
m
p
l
e

f
o
o

PS C:\> 'example blabla' | Fold -w:5
examp
le bl
abla

关于powershell - PowerShell中的特定bash命令(折叠-w1)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20442878/

相关文章:

powershell - 无法添加类型Microsoft.TeamFoundation.Client

powershell - 我可以为 PowerShell 中的参数指定条件默认值吗?

haskell - foldr 和 foldl 的高阶函数细节

lambda - 尾随 lambda 语法 (Kotlin) 的目的是什么?

linux - 如何获得在 Linux 上运行的全功能 PowerShell?

windows - 如何在批处理文件或 PowerShell 脚本中多次运行命令 'x'?

Scala:避免在foldLeft中强制转换为类型参数

haskell - (>>=) 折叠时的惰性

haskell - mapEvery可以用foldr实现吗

powershell - Powershell用arg启动/停止