Here you can find the source of chomp(String inStr)
Parameter | Description |
---|---|
inStr | The String to work on. |
public static String chomp(String inStr)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009 MATERNA Information & Communications. 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. For further * project-related information visit http://www.ws4d.org. The most recent * version of the JMEDS framework can be obtained from * http://sourceforge.net/projects/ws4d-javame. ******************************************************************************/ public class Main { /**/* ww w . java 2 s . c o m*/ * Deletes the Line Feed (10) and Carriage Return (13) fields of the given * String. * * @param inStr The String to work on. * @return The string without Line Feed and Carriage Return. */ public static String chomp(String inStr) { if (inStr == null || "".equals(inStr)) { return inStr; } char lastChar = inStr.charAt(inStr.length() - 1); if (lastChar == 13) { // if the string ends with Carriage Return return inStr.substring(0, inStr.length() - 1); } else if (lastChar == 10) { // if the string ends with Line Feed String tmp = inStr.substring(0, inStr.length() - 1); if ("".equals(tmp)) { return tmp; } lastChar = tmp.charAt(tmp.length() - 1); // if the string also contains Carriage Return if (lastChar == 13) { return tmp.substring(0, tmp.length() - 1); } else { return tmp; } } else { return inStr; } } }