splitting or cropping a variable value in powershell

DevSupport
DevSupport used Ask the Experts™
on
Hi Experts,

In powershell I have a variable which has value

$var=C:\Tomcat8032_app\apache-tomcat\bin\tomcat8.exe //RS//dsupgdev

I want to crop this string and store the value to another variable such that I want only the values until 3rd backslash "\"

$new-var=C:\Tomcat8032_app\apache-tomcat\

Could you please help me with this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Technical Specialist
Awarded 2017
Distinguished Expert 2018
Commented:
$new-var = $var.split("\")[0] + "\" + $var.split("\")[1] + "\" + $var.split("\")[2] + "\"

Open in new window

Author

Commented:
Thank You Shaun!!
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
Anytime, happy to help

Please remember to Endorse my, or any other expert's, comment that you found helpful.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial