开发者

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

开发者 https://www.devze.com 2023-02-16 12:13 出处:网络
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.

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

精彩评论

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