Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A possible solution:</p> <p>Loop trough your list of paths, split them on the backslash character and then loop trough every value of the resulting array. See how long it equals the values of your reference path and give them a score accordingly. My example is a little rough, but you can adjust it accordingly.</p> <pre><code>public class PathScore { public String Path; public int Score; } public class Systempaths { public static void main(String[] args) { new Systempaths(); } public Systempaths() { String[] paths = new String[5]; paths[0] = "C:\\System\\local\\something\\anything"; paths[1] = "C:\\System\\local\\anywhere\\somewhere"; paths[2] = "C:\\System\\local"; paths[3] = "C:\\System\\"; paths[4] = "C:\\something\\somewhere"; String ref = "C:\\System\\local\\test\\anything"; String[] reference = ref.split("\\\\"); List&lt;PathScore&gt; scores = new ArrayList&lt;&gt;(); for (String s : paths) { String[] exploded = s.split("\\\\"); PathScore current = new PathScore(); current.Path = s; for (int i = 0; i &lt; exploded.length; i++) { if (exploded[i].equals(reference[i])) { current.Score = i + 1; } else { // Punishment for paths that exceed the reference path (1) current.Score = i - 1; break; } } scores.add(current); } for (PathScore ps : scores) { System.out.printf("%s:\t%d\n", ps.Path, ps.Score); } } } </code></pre> <p>Outputs:</p> <pre><code>C:\System\local\something\anything: 2 C:\System\local\anywhere\somewhere: 2 C:\System\local: 3 C:\System\: 2 C:\something\somewhere: 0 </code></pre> <p>(1): I add a small punishment for paths (like <code>C:\System\local\something\anything</code>) that are too specific and go further than the reference path (<code>"C:\System\local\test\anything"</code>) allows.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload