Java String Clip clip(String characterItem)

Here you can find the source of clip(String characterItem)

Description

clip

License

Open Source License

Declaration

public static String clip(String characterItem) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright ? 2006, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  ww w  . ja  v  a  2s.  co m
 * IBM Corporation - initial API and implementation
 *
 *******************************************************************************/

public class Main {
    public static String clip(String characterItem) {
        int length = characterItem.length();
        if (length > 0) {
            int startingIdx = length - 1;
            boolean charsDeleted = false;
            while (startingIdx >= 0) {
                char c = characterItem.charAt(startingIdx);
                if (c <= ' ' || c == '\u3000') {
                    charsDeleted = true;
                    startingIdx--;
                } else {
                    break;
                }
            }
            if (charsDeleted) {
                return characterItem.substring(0, startingIdx + 1);
            }
        }
        return characterItem;
    }
}

Related

  1. clip(final String s, final int leftClip, final int rightClip)
  2. clip(String str, int startChars)
  3. ClipObjectReferenceAddress(String p_fullObjectReference)
  4. clipString(String input, int numChars, boolean appendEllipses)
  5. clipText(String text, int maxLength)