开发者

Is there a way in PowerShell to truncate a string without cutting short a word

I've been looking around and haven't been able to find anything. I would like to truncate a string without cutti开发者_如何学运维ng a word short. Like an excerpt.

$string = "This is my string"

9 = "This is m"

Ideally would like "This is my"


$string.Substring(0, $string.IndexOf(" ", 9))

Should do what you want, i.e. it starts at the character number you give it, looks for the next space, and cuts the string short there.


Do you mean $string.Substring(0,$string.lastindexof(" ")) ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜