Welcome › Forums › General PowerShell Q&A › Extract Certain Length of Characters From Delimiter
I’m trying to extract certain content from the return of one of my scripts. The return value has a delimiter of ‘/’.
Here’s an example:
I’d like to pull the value after the last delimiter ‘/’.
Any idea on how to extract that content?
$value = “/subscriptions/f873d82f-7491-4045-8dbe/resourceGroups/use2-dev-rg” -split “/”
$lastsplit = $value[$value.count -1]
heres one approach, if the number of / will always be the same, then you can reference it as $value
Another method is using GetUpperBound:
$value = "/subscriptions/f873d82f-7491-4045-8dbe/resourceGroups/use2-dev-rg" -split "/"
# Get last string in array after splitting
$string = '/subscriptions/f873d82f-7491-4045-8dbe/resourceGroups/use2-dev-rg'
All of them work great, but the I’m going to use:
It was easier to add to my existing code than the others and returns exactly what I need.
I appreciate everyone’s help! Thx!