Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Remove index and '-' from layer name.
     * 
     * @param name
     * @return
     */
    public static String removeIndex(String name) {
        int last = name.lastIndexOf("-");

        if (name.length() == (last + 1)) {
            // ends with - not indexed
            return name;
        }

        String indx = name.substring(last + 1);
        try {
            // try to parse string after "-" as integer
            Long.parseLong(indx);
            // ok, remove index
            return name.substring(0, last);
        } catch (Exception ex) {
            // not valid, not index
            return name;
        }

    }
}