Created
March 11, 2020 14:42
-
-
Save flaudanum/7c8bbece77406c9c48f91f7b799e079d to your computer and use it in GitHub Desktop.
Remove ending backslash and trailing space from a Windows path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String winPath = "C:\\Users\\f.laudanum\\Documents\\My-Directory\\ "; | |
| String cleanPath; | |
| /* REGEXP pattern: '\\\s*' with doubled backslashes */ | |
| Pattern pattern = Pattern.compile("\\\\\\s*$"); | |
| Matcher match = pattern.matcher(winPath); | |
| /* Call to find(0) triggers the pattern search from text's start*/ | |
| if (match.find(0)) { | |
| cleanPath = match.replaceAll(""); | |
| } else { | |
| cleanPath = winPath; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment