Java String Ends With endsWithoutPathSeparator(final String path)

Here you can find the source of endsWithoutPathSeparator(final String path)

Description

Make sure a given path does not end with a path separator character.

License

Apache License

Parameter

Parameter Description
path the prospective path.

Return

the path guaranteed to NOT end with a path separator character.

Declaration

public static String endsWithoutPathSeparator(final String path) 

Method Source Code

//package com.java2s;
//   Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /**/*from   w ww  . j a va2  s . co m*/
     * Make sure a given path does not end with a path separator character.
     *
     * @param path the prospective path.
     * @return the path guaranteed to NOT end with a path separator character.
     */
    public static String endsWithoutPathSeparator(final String path) {
        String returnedPath;
        if (path.endsWith("/") || path.endsWith("\\")) {
            returnedPath = path.substring(0, path.length() - 1);
        } else {
            returnedPath = path;
        }
        return returnedPath;
    }
}

Related

  1. endsWithName(String subject, String endName)
  2. endsWithNewline(String string)
  3. endsWithOne(final String src, final String[] dest)
  4. endsWithOne(String src, String... dest)
  5. endsWithOneOf(String value, String... ends)
  6. endsWithoutSlash(String url)
  7. endsWithSentenceSeparator(char[] token)
  8. endsWithSeparator(String str)
  9. endsWithSingleQuoteS(String s)