Java String Sub String substringBefore(String text, String str)

Here you can find the source of substringBefore(String text, String str)

Description

substring Before

License

Open Source License

Declaration

public final static String substringBefore(String text, String str) 

Method Source Code

//package com.java2s;
/*  Copyright (c) 2010 Xiaoyun Zhu
 * /*from   ww w  .jav  a2 s.c  o  m*/
 *  Permission is hereby granted, free of charge, to any person obtaining a copy  
 *  of this software and associated documentation files (the "Software"), to deal  
 *  in the Software without restriction, including without limitation the rights  
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
 *  copies of the Software, and to permit persons to whom the Software is  
 *  furnished to do so, subject to the following conditions:
 *  
 *  The above copyright notice and this permission notice shall be included in  
 *  all copies or substantial portions of the Software.
 *  
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN  
 *  THE SOFTWARE.  
 */

public class Main {
    public final static String substringBefore(String text, String str) {
        int idx = text.indexOf(str);
        if (idx != -1) {
            return text.substring(0, idx);
        } else {
            return null;
        }
    }
}

Related

  1. substringBefore(String str, int endChar)
  2. substringBefore(String str, String separator)
  3. substringBefore(String str, String separator)
  4. substringBefore(String str, String separator)
  5. substringBefore(String string, String delimiter)
  6. substringBeforeChar(String str, int separator)
  7. substringBeforeFirst(String string, String delimiter)
  8. subStringBeforeFirstTab(final String s)
  9. substringBeforeLast(final String str, final String separator)