December 20, 2019 at 3:44 pm #194639ParticipantTopics: 14Replies: 22Points: 186Rank: Participant
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?
December 20, 2019 at 4:02 pm #194660ParticipantTopics: 23Replies: 163Points: 471Rank: Contributor
$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
December 20, 2019 at 4:08 pm #194663ParticipantTopics: 10Replies: 1375Points: 1,481Rank: Community Hero
Another method is using GetUpperBound:
$value = "/subscriptions/f873d82f-7491-4045-8dbe/resourceGroups/use2-dev-rg" -split "/" $value[$value.GetUpperBound(0)]
December 20, 2019 at 4:40 pm #194681ParticipantTopics: 5Replies: 285Points: 213Rank: Participant
# Get last string in array after splitting $string = '/subscriptions/f873d82f-7491-4045-8dbe/resourceGroups/use2-dev-rg' $string.Split('/')[-1]
December 20, 2019 at 6:02 pm #194699ParticipantTopics: 14Replies: 22Points: 186Rank: Participant
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!
- You must be logged in to reply to this topic.