Java String Split splitMultiMessageString( String multiMessageString, String messageSplitter)

Here you can find the source of splitMultiMessageString( String multiMessageString, String messageSplitter)

Description

Splits a multi-message string into several message strings.

License

Open Source License

Declaration

public static List<String> splitMultiMessageString(
        String multiMessageString, String messageSplitter) 

Method Source Code

//package com.java2s;
/* The MIT License (MIT)

 Copyright (c) 2012 Jerome Wagener//w  w w .jav a  2 s  . com

 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.*/

import java.util.ArrayList;
import java.util.List;

public class Main {
    /** Splits a multi-message string into several message strings. If the provided string only contains 
     * one message, only this message will be returned. If the multiMessageString does not contain at 
     * least one message splitter string, the original string will be returned */
    public static List<String> splitMultiMessageString(
            String multiMessageString, String messageSplitter) {
        ArrayList<String> messages = new ArrayList<String>();

        if (multiMessageString.startsWith(messageSplitter)) {
            for (String message : multiMessageString.split(messageSplitter)) {
                if (!(message.trim()).isEmpty()) {
                    messages.add(messageSplitter + message);
                }
            }

            return messages;
        }

        messages.add(multiMessageString);

        return messages;
    }
}

Related

  1. splitLists(String s)
  2. splitListToParts(final List list, final int times)
  3. splitLongUnicodeString(String message, List result)
  4. splitMacros(String s)
  5. splitManagedBean(String el)
  6. splitName(String name)
  7. splitNames(final String string)
  8. splitObjectString(String str)
  9. splitOgnl(String ognl)