Ferfa
Ferfa

Reputation: 221

How to remove the left side of this string?

My string is:

$dst = "Folder_1\SubFolder_2\3\4\5"

My goal is to have:

$dst_OK = "SubFolder_2\3\4\5"

I tried use split function like this:

$dst_OK = $dst.split("\")[0]  

but the result is Folder_1 only.

Upvotes: 2

Views: 543

Answers (4)

Esperento57
Esperento57

Reputation: 17472

Solution 2

$dst.Substring($dst.IndexOf('\')+1)

Upvotes: 0

Esperento57
Esperento57

Reputation: 17472

Other solution :

($dst -split "\\", 2)[1]

Upvotes: 0

k7s5a
k7s5a

Reputation: 1377

You can do it with this snippet:

$first, $rest = "Folder_1\SubFolder_2\3\4\5" -split '\\'
$rest = $rest -join '\'

Upvotes: 0

Martin Brandl
Martin Brandl

Reputation: 58931

You could use the following regex to remove the left side of the string:

$dst_OK = $dst -replace '^.*?\\'

However, since it looks like you are dealing with a path, you may consider to using builtin function within the System.IO.Path namespace.

Upvotes: 1

Related Questions