Wer*_*rCD 2 regex string powershell
我正试图在power-shell中分割一个字符串...我已经对字符串做了一些工作,但我无法弄清楚这最后一部分.
说我坐在这个字符串:
This is a string. Its a comment that's anywhere from 5 to 250 characters wide.
Run Code Online (Sandbox Code Playgroud)
我想把它拆分为30个字符,但我不想分开一个单词.如果我要将它分开,它会在一行上有"...... commen"......下一行就是"那个......".
什么是优雅的方式来分割字符串,50max,而不会破坏一个字?为简单起见,一个单词就是一个空格(注释中也可能有数字文本"$ 1.00".也不想将其分成两半).
$regex = [regex] "\b"
$str = "This is a string. Its a comment that's anywhere from 5 to 250 characters wide."
$split = $regex.split($str, 2, 30)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8180 次 |
| 最近记录: |