Java String Extract extractField(int position, String regex, String source)

Here you can find the source of extractField(int position, String regex, String source)

Description

extract Field

License

Open Source License

Declaration

public static String extractField(int position, String regex, String source) 

Method Source Code

//package com.java2s;
/*/*from   w w w . ja va  2  s  .  c om*/
 * gMix open source project - https://svs.informatik.uni-hamburg.de/gmix/
 * Copyright (C) 2012  Karl-Peter Fuchs
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Arrays;

public class Main {
    public static String extractField(int position, String regex, String source) {
        String[] splitted = source.split(regex, position + 2);
        return splitted[position];
    }

    public static byte[][] split(int splitBefore, byte[] source) {
        if (source.length <= splitBefore)
            throw new RuntimeException("cannot split the bypassed array (array too small: " + source.length + "<="
                    + splitBefore + ")");
        byte[][] result = new byte[2][];
        result[0] = Arrays.copyOfRange(source, 0, splitBefore);
        result[1] = Arrays.copyOfRange(source, splitBefore, source.length);
        return result;
    }
}

Related

  1. extractArrayData(String input, StringBuilder output)
  2. extractArrayData(String input, StringBuilder output)
  3. extractCharNgram(String content, int n)
  4. extractCommands(String fileContents)
  5. extractData(String message)
  6. extractGenericTypeNames(String sig)
  7. extractHorizontalTabs(String line, int tabSize)
  8. extractItems(String items)
  9. extractJobId(String line)