Here you can find the source of clipString(String input, int numChars, boolean appendEllipses)
Parameter | Description |
---|---|
input | The string to clip |
numChars | the number of leading chars to keep (all others will be removed) |
public static String clipString(String input, int numChars, boolean appendEllipses)
//package com.java2s; /*//from w w w . ja v a 2s . com * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ public class Main { /** * Reduces the input string to the number of chars, or its length if the * number of chars exceeds the input string's length * * @param input The string to clip * @param numChars the number of leading chars to keep (all others will be * removed) * @return: the clipped string */ public static String clipString(String input, int numChars, boolean appendEllipses) { int end = Math.min(numChars, input.length()); String output = input.substring(0, end); if (appendEllipses) { output = (output.length() < input.length()) ? output + "..." : output; } return output; } }