Example usage for java.lang String split

List of usage examples for java.lang String split

Introduction

In this page you can find the example usage for java.lang String split.

Prototype

public String[] split(String regex, int limit) 

Source Link

Document

Splits this string around matches of the given regular expression.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    String s = "|A|BB|CCC||||";
    String[] words = s.split("\\|", -1);
    for (String string : words) {
        System.out.println(">" + string + "<");
    }/*from ww w  . jav a 2s.c om*/
}

From source file:MainClass.java

public static void main(String[] arg) {
    String text = "to be or not to be, that is the question.";
    String[] words = text.split("[, .]", 0); // Delimiters are comma, space, or period

    for (String s : words) {
        System.out.println(s);/*  w w w  .  jav  a  2s.com*/
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    String inputStr = "a, b, c,d";
    String patternStr = ", ";
    String[] fields = inputStr.split(patternStr, -1);
}

From source file:Main.java

public static void main(String args[]) {
    String str = "one.two.three";
    String delimeter = "\\.";

    String[] temp = str.split(delimeter, 2);
    for (int i = 0; i < temp.length; i++) {
        System.out.println(temp[i]);
    }/* w  w w. j  a v  a 2 s. c o m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    String inputStr = "a, b, and c";
    String patternStr = "[, ]+(and|or)*[, ]*";
    String[] fields = inputStr.split(patternStr, -1);
}

From source file:Main.java

public static void main(String[] arg) {
    String text = "To be or not to be, that is the question.";
    String delimiters = "[, .]";
    int[] limits = { 0, -1 };
    for (int limit : limits) {
        System.out.println("\nAnalysis with limit = " + limit);
        String[] tokens = text.split(delimiters, limit);
        System.out.println("Number of tokens: " + tokens.length);
        for (String token : tokens) {
            System.out.println(token);
        }//  w w w .j av  a2 s  .c  o m
    }
}

From source file:com.sebuilder.interpreter.SeInterpreter.java

public static void main(String[] args) {
    if (args.length == 0) {
        System.out.println(//  ww  w . j a va  2  s.c  o m
                "Usage: [--driver=<drivername] [--driver.<configkey>=<configvalue>...] [--implicitlyWait=<ms>] [--pageLoadTimeout=<ms>] [--stepTypePackage=<package name>] <script path>...");
        System.exit(0);
    }

    Log log = LogFactory.getFactory().getInstance(SeInterpreter.class);

    WebDriverFactory wdf = DEFAULT_DRIVER_FACTORY;
    ScriptFactory sf = new ScriptFactory();
    StepTypeFactory stf = new StepTypeFactory();
    sf.setStepTypeFactory(stf);
    TestRunFactory trf = new TestRunFactory();
    sf.setTestRunFactory(trf);

    ArrayList<String> paths = new ArrayList<String>();
    HashMap<String, String> driverConfig = new HashMap<String, String>();
    for (String s : args) {
        if (s.startsWith("--")) {
            String[] kv = s.split("=", 2);
            if (kv.length < 2) {
                log.fatal("Driver configuration option \"" + s
                        + "\" is not of the form \"--driver=<name>\" or \"--driver.<key>=<value\".");
                System.exit(1);
            }
            if (s.startsWith("--implicitlyWait")) {
                trf.setImplicitlyWaitDriverTimeout(Integer.parseInt(kv[1]));
            } else if (s.startsWith("--pageLoadTimeout")) {
                trf.setPageLoadDriverTimeout(Integer.parseInt(kv[1]));
            } else if (s.startsWith("--stepTypePackage")) {
                stf.setPrimaryPackage(kv[1]);
            } else if (s.startsWith("--driver.")) {
                driverConfig.put(kv[0].substring("--driver.".length()), kv[1]);
            } else if (s.startsWith("--driver")) {
                try {
                    wdf = (WebDriverFactory) Class
                            .forName("com.sebuilder.interpreter.webdriverfactory." + kv[1]).newInstance();
                } catch (ClassNotFoundException e) {
                    log.fatal("Unknown WebDriverFactory: " + "com.sebuilder.interpreter.webdriverfactory."
                            + kv[1], e);
                } catch (InstantiationException e) {
                    log.fatal("Could not instantiate WebDriverFactory "
                            + "com.sebuilder.interpreter.webdriverfactory." + kv[1], e);
                } catch (IllegalAccessException e) {
                    log.fatal("Could not instantiate WebDriverFactory "
                            + "com.sebuilder.interpreter.webdriverfactory." + kv[1], e);
                }
            } else {
                paths.add(s);
            }
        } else {
            paths.add(s);
        }
    }

    if (paths.isEmpty()) {
        log.info("Configuration successful but no paths to scripts specified. Exiting.");
        System.exit(0);
    }

    HashMap<String, String> cfg = new HashMap<String, String>(driverConfig);

    for (String path : paths) {
        try {
            TestRun lastRun = null;
            for (Script script : sf.parse(new File(path))) {
                for (Map<String, String> data : script.dataRows) {
                    try {
                        lastRun = script.testRunFactory.createTestRun(script, log, wdf, driverConfig, data,
                                lastRun);
                        if (lastRun.finish()) {
                            log.info(script.name + " succeeded");
                        } else {
                            log.info(script.name + " failed");
                        }
                    } catch (Exception e) {
                        log.info(script.name + " failed", e);
                    }
                }
            }
        } catch (Exception e) {
            log.fatal("Run error.", e);
            System.exit(1);
        }
    }
}

From source file:org.datagator.api.client.backend.DataGatorService.java

public static void main(String[] args) throws Exception {
    UsernamePasswordCredentials auth = null;
    String credentials = environ.DATAGATOR_CREDENTIALS;
    if (credentials != null) {
        String[] tuple = credentials.split(".", 1);
        if (tuple.length > 1) {
            auth = new UsernamePasswordCredentials(tuple[0], tuple[1]);
        } else if (tuple.length > 0) {
            auth = new UsernamePasswordCredentials(tuple[0], null);
        }/*  w ww . j a v  a  2  s.c  om*/
    }

    final DataGatorService service;
    if (auth != null) {
        service = new DataGatorService(auth);
    } else {
        service = new DataGatorService();
    }

    CloseableHttpResponse response = service.get("/");
    response.getEntity().writeTo(System.out);
    response.close();

    // JsonParser parser = json.createParser(stream);
}

From source file:MainClass.java

public static void main(String[] arg) {
    String text = "To be or not to be, that is the question.";
    String delimiters = "[, .]"; // Delimiters are comma, space, and period
    int[] limits = { 0, -1 }; // Limit values to try

    for (int limit : limits) {
        System.out.println("\nAnalysis with limit = " + limit);
        String[] tokens = text.split(delimiters, limit);
        System.out.println("Number of tokens: " + tokens.length);
        for (String token : tokens) {
            System.out.println(token);
        }/* ww  w .ja  v  a 2s  .  c  om*/
    }

}

From source file:org.objectrepository.MessageConsumerDaemon.java

/**
 * main//from  ww w . j  a  v a 2  s .  co  m
 * <p/>
 * Accepts one folder as argument:  -messageQueues
 * That folder ought to contain one or more folders ( or symbolic links ) to the files
 * The folder has the format: [foldername] or [foldername].[maxTasks]
 * MaxTasks is to indicate the total number of jobs being able to run.
 *
 * long
 *
 * @param argv
 */
public static void main(String[] argv) {

    if (instance == null) {
        final Properties properties = new Properties();

        if (argv.length > 0) {
            for (int i = 0; i < argv.length; i += 2) {
                try {
                    properties.put(argv[i], argv[i + 1]);
                } catch (ArrayIndexOutOfBoundsException arr) {
                    System.out.println("Missing value after parameter " + argv[i]);
                    System.exit(-1);
                }
            }
        } else {
            log.fatal("Usage: pmq-agent.jar -messageQueues [queues] -heartbeatInterval [interval in ms]\n"
                    + "The queues is a folder that contains symbolic links to the startup scripts.");
            System.exit(-1);
        }

        if (log.isInfoEnabled()) {
            log.info("Arguments set: ");
            for (String key : properties.stringPropertyNames()) {
                log.info("'" + key + "'='" + properties.getProperty(key) + "'");
            }
        }

        if (!properties.containsKey("-messageQueues")) {
            log.fatal("Expected case sensitive parameter: -messageQueues");
            System.exit(-1);
        }

        final File messageQueues = new File((String) properties.get("-messageQueues"));
        if (!messageQueues.exists()) {
            log.fatal("Cannot find folder for messageQueues: " + messageQueues.getAbsolutePath());
            System.exit(-1);
        }

        if (messageQueues.isFile()) {
            log.fatal(
                    "-messageQueues should point to a folder, not a file: " + messageQueues.getAbsolutePath());
            System.exit(-1);
        }

        long heartbeatInterval = 600000;
        if (properties.containsKey("-heartbeatInterval")) {
            heartbeatInterval = Long.parseLong((String) properties.get("heartbeatInterval"));
        }

        String identifier = null;
        if (properties.containsKey("-id")) {
            identifier = (String) properties.get("-id");
        } else if (properties.containsKey("-identifier")) {
            identifier = (String) properties.get("-identifier");
        }

        final File[] files = messageQueues.listFiles();
        final String[] scriptNames = (properties.containsKey("-startup"))
                ? new String[] { properties.getProperty("-startup") }
                : new String[] { "/startup.sh", "\\startup.bat" };
        final List<Queue> queues = new ArrayList<Queue>();
        for (File file : files) {
            final String name = file.getName();
            final String[] split = name.split("\\.", 2);
            final String queueName = split[0];
            for (String scriptName : scriptNames) {
                final String shellScript = file.getAbsolutePath() + scriptName;
                final int maxTask = (split.length == 1) ? 1 : Integer.parseInt(split[1]);
                log.info("Candidate mq client for " + queueName + " maxTasks " + maxTask);
                if (new File(shellScript).exists()) {
                    final Queue queue = new Queue(queueName, shellScript, false);
                    queue.setCorePoolSize(1);
                    queue.setMaxPoolSize(maxTask);
                    queue.setQueueCapacity(1);
                    queues.add(queue);
                    break;
                } else {
                    log.warn("... skipping, because no startup script found at " + shellScript);
                }
            }
        }

        if (queues.size() == 0) {
            log.fatal("No queue folders seen in " + messageQueues.getAbsolutePath());
            System.exit(-1);
        }

        // Add the system queue
        queues.add(new Queue("Connection", null, true));

        getInstance(queues, identifier, heartbeatInterval).run();
    }
    System.exit(0);
}