Here you can find the source of substring(String s, int start, int stop)
Parameter | Description |
---|---|
s | a parameter |
start | a parameter |
stop | a parameter |
public static final String substring(String s, int start, int stop)
//package com.java2s; /**// www.j a va 2 s. c o m * Copyright 2011 Marco Berri - marcoberri@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License 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 { /** * * @param s * @param start * @param stop * @return string */ public static final String substring(String s, int start, int stop) { if (isEmpty(s)) { return s; } if (start < 0 || start >= s.length()) { return ""; } if (stop > s.length() || stop < 0) { stop = s.length(); } return s.substring(start, stop); } /** * * @param s * @param start * @return string */ public static final String substring(String s, int start) { return substring(s, start, -1); } /** * Checks if a String is empty or null * * @param s String to check * @return true if null or empty, false otherwise */ public static boolean isEmpty(String s) { return (s == null || "".equals(s.trim())); } /** * * @param s * @param alt * @return */ public static String isEmpty(String s, String alt) { if (isEmpty(s)) { return alt; } return s; } /** * Esegue una Trim su una Stringa * se s == null return null * * @param s String to trim * @return La Stringa Trimmata */ public static final String trim(String s) { if (s == null) { return null; } return s.trim(); } }