Java String Shorten shortenToFirstLast(String filename)

Here you can find the source of shortenToFirstLast(String filename)

Description

shorten To First Last

License

Open Source License

Declaration

public static String shortenToFirstLast(String filename) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String shortenToFirstLast(String filename) {
        if ((filename == null) || (filename.length() < 2)) {
            return filename;
        }//  www .j  a  va2s .c o m

        final int firstIndex = filename.indexOf('/', 1);
        final int lastIndex = filename.lastIndexOf('/');

        if ((firstIndex < 0) || (firstIndex == lastIndex)) {
            return filename;
        }

        String result = filename.substring(0, firstIndex) + filename.substring(lastIndex);
        return result;
    }
}

Related

  1. shortenText(int maxWidth, String textValue)
  2. shortenText(String originalText, int maxlength)
  3. shortenText(String string, int threshold)
  4. shortenTo(final String value, final int maxLength)
  5. shortenTo(String string, int lenght)
  6. shortenType(String typeText)
  7. shortenURI(String uri)
  8. shortenUrl(String protocolHostPart, String pathPart, String queryPart, String fragmentIdentifier)
  9. ShortenVector(double[] vector, int new_length)