gpt4 book ai didi

regex - Powershell - 拆分字符串

转载 作者:行者123 更新时间:2023-12-02 07:40:03 26 4
gpt4 key购买 nike

我正在尝试在 power-shell 中拆分字符串...我已经对字符串做了一些工作,但我无法弄清楚最后一部分。

假设我正坐在这个字符串上:

This is a string. Its a comment that's anywhere from 5 to 250 characters wide.

我想在 30 个字符标记处拆分它,但我不想拆分一个词。如果我要拆分它,它会在一行上有“...commen”...“t that...”在下一行。

在不将单词分成两半的情况下,将字符串 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)

关于regex - Powershell - 拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12144327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com