Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell remove text after first instance of special character

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

like image 976
runcmd Avatar asked Jun 04 '14 17:06

runcmd


2 Answers

$s = '8.2.4.151.65; HBAAPI(I) v1.3; 3-29-02'
$s.Substring(0, $s.IndexOf(';'))
like image 179
Doug Finke Avatar answered Sep 17 '22 23:09

Doug Finke


Split on the ; and take the first string.

'8.2.4.151.65; HBAAPI(I) v1.3; 3-29-02'.split(';')[0] 
like image 33
Rynant Avatar answered Sep 19 '22 23:09

Rynant