Java String Split splitTemplateName(String templateName)

Here you can find the source of splitTemplateName(String templateName)

Description

Splits template name to get identifier, field name and locale

License

Apache License

Parameter

Parameter Description
templateName String in form <code>identifier_field_locale</code>

Return

Array containing identifier, field and locale or empty array if string format is incorrect

Declaration

public static String[] splitTemplateName(String templateName) 

Method Source Code

//package com.java2s;
/*/*from  w  ww  .  ja  v  a2s  . c om*/
 *
 *  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.
 */

import java.util.*;

public class Main {
    /**
     * Splits template name to get identifier, field name and locale
     * 
     * @param templateName
     *            String in form <code>identifier_field_locale</code>
     * @return Array containing identifier, field and locale or empty array if
     *         string format is incorrect
     */
    public static String[] splitTemplateName(String templateName) {
        ArrayList result = new ArrayList();
        int k = templateName.lastIndexOf("_");
        if (k != -1) {
            String locale = templateName.substring(k + 1);
            templateName = templateName.substring(0, k);
            k = templateName.lastIndexOf("_");
            if (k != -1) {
                String field = templateName.substring(k + 1);
                templateName = templateName.substring(0, k);
                result.add(templateName);
                result.add(field);
                result.add(locale);
            }
        }
        return (String[]) result.toArray(new String[0]);
    }
}

Related

  1. splitStringWithoutTrim(String strInput, String strSplitor)
  2. splitStruct(String struct)
  3. splitSubstring(String str, String substr)
  4. splitTags(final String tagsString)
  5. splitTags(String rawTags)
  6. splitter(List list, final int L)
  7. splitTerms(String queryString)
  8. splitText(String text)
  9. splitToInteger(String str)