Question: How do I make it so that a desktop UWP app will resize based on resolution? Mainly I need it to work between a surface pro and a Surface Studio. I've researched around google and I haven't seen anything that goes into detail. I know of things like RelativePanel and VisualStateManagers, but I have not clue how to use them. Any guidance would be much appreciated.

Answer: 
There are many alternative ways:

1. Use Java-Stream API on splitted String with `\` delimiter:

```
String str = "/service1/api/v1.0/foo/{fooId}/boo";  
String[] split = str.split("\\/");
String url = Arrays.stream(split).skip(4).collect(Collectors.joining("/"));
System.out.println(url);

```

With the elimination of the parameter, the Stream would be like:

```
String url = Arrays.stream(split)
    .skip(4)
    .map(i -> i.replaceAll("\\?.+", ""))
    .collect(Collectors.joining("/"));

```
2. This is also where [Regex](https://regex101.com/r/yB3Ouo/1) takes its place! Use the classes Pattern and Matcher.

```
String str = "/service1/api/v1.0/foo/{fooId}/boo";

Pattern pattern = Pattern.compile("\\/.*?\\/api\\/v\\d+\\.\\d+\\/(.+)");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
    System.out.println(matcher.group(1));
}

```

---

If you rely on the `indexOf(..)` usage, you might want to use the while-loop.

```
String str = "/service1/api/v1.0/foo/{fooId}/boo?parameter=value"; 

String string = str;
while(!string.startsWith("v1.0")) {
    string = string.substring(string.indexOf("/") + 1);
}

System.out.println(string.substring(string.indexOf("/") + 1, string.indexOf("?")));

```

Other answers include a way that if the prefix is not mutable, you might want to use only one call of `idndexOf(..)` method ([@JB Nizet](https://stackoverflow.com/users/571407/jb-nizet)):

```
string.substring("/service1/api/v1.0/".length(), string.indexOf("?"));

```

---

All these solutions are based on your input and fact, the pattern is known, or at least the number of the previous section delimited with `\` or the version `v1.0` as a checkpoint - the best solution might not appear here since there are unlimited combinations of the URL. You have to know all the possible combinations of input URL to find the best way to handle it.
There are a few good options here.

1) If you know "foo" will always be the 4th token, then you have the right idea already. The only issue with your way is that you have the information you need to be efficient, but you aren't using it. Instead of copying the String multiple times and looping anew from the beginning of the new String, you could just continue from where you left off, 4 times, to find the starting point of what you want.

```
String str = "/service1/api/v1.0/foo/{fooId}/boo";

// start at the beginning
int start = 0;
// get the 4th index of '/' in the string
for (int i = 0; i != 4; i++) {
    // get the next index of '/' after the index 'start'
    start = str.indexOf('/',start);
    // increase the pointer to the next character after this slash
    start++;
}
// get the substring
str = str.substring(start);

```

This will be far, far more efficient than any regex pattern.

2) Regex: (java.util.regex.\*). This will work if you what you want is always preceded by `"service1/api/v1.0/"`. There may be other directories before it, e.g. `"one/two/three/service1/api/v1.0/"`.

```
// \Q \E will automatically escape any special chars in the path
// (.+) will capture the matched text at that position
// $ marks the end of the string (technically it matches just before '\n')
Pattern pattern = Pattern.compile("/service1/api/v1\\.0/(.+)$");
// get a matcher for it
Matcher matcher = pattern.matcher(str);
// if there is a match
if (matcher.find()) {
    // get the captured text
    str = matcher.group(1);
}

```

If your path can vary some, you can use regex to account for it. e.g.: service/api/v3/foo/{bar}/baz/" (note varying number formats and trailing '/') could be matched as well by changing the regex to `"/service\\d*/api/v\\d+(?:\\.\\d+)?/(.+)(?:/|$)"`