I have a string
that looks like this: Value->Value2->Value3->ImportantValue->val
.
I would like to extract ImportantValue
. I have read other posts concerning this question but none of them works for me. I tried this:
int pFrom = path.IndexOf("->") + "->".Length;
int pTo = path.LastIndexOf("->val");
String result = path.Substring(pFrom, pTo - pFrom);
It returns Value2->Value3->ImportantValue->val
because it gives out the string between the first ->
and ->val
. Any ideas on how I would change the above code so that it returns ImportantValue
? Thanks in advance.
EDIT
Sorry, I forgot to specify that ImportantValue
is always different. The entire string also changes, meaning it will have more three Values
. But the ImportantValue
is always the second to last element so I will mark the answer from Paul Kertscher as the right one and upvote the other similar answers.