Powershell remove text after first instance of spe

2019-07-01 08:57发布

This is the value that I have to parse.

8.2.4.151.65; HBAAPI(I) v1.3; 3-29-02

I need to remove everything after and including the first instance of ;

So I need my ending result to be 8.2.4.151.65

3条回答
劳资没心,怎么记你
2楼-- · 2019-07-01 09:32

Split on the ; and take the first string.

'8.2.4.151.65; HBAAPI(I) v1.3; 3-29-02'.split(';')[0] 
查看更多
做个烂人
3楼-- · 2019-07-01 09:38
$s = '8.2.4.151.65; HBAAPI(I) v1.3; 3-29-02'
$s.Substring(0, $s.IndexOf(';'))
查看更多
ゆ 、 Hurt°
4楼-- · 2019-07-01 09:53

Using a regex with a lazy match:

'8.2.4.151.65; HBAAPI(I) v1.3; 3-29-02' -replace '(.+?);.+','$1'

8.2.4.151.65

The ? makes the match 'lazy', so it stop at the first ;

查看更多
登录 后发表回答