Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Will remove all occurrences of the characters '<', '>', '[', ']', '{' and '}'
     * from the input string and return the result. Beware: While <code>chopBraces()</code>
     * only removes those characters from the beginning and end of a string, <code>stripBraces()</code>
     * will remove characters from all positions in the string.
     * @param s
     * @return
     */
    public static String stripBraces(String s) {
        char c[] = s.toCharArray();
        char tmp[] = new char[c.length];

        int id = 0;
        for (int i = 0; i < c.length; i++) {
            char cc = c[i];
            if (cc != '<' && cc != '>' && cc != '[' && cc != ']' && cc != '{' && cc != '}')
                tmp[id++] = c[i];
        }

        char res[] = new char[id];
        System.arraycopy(tmp, 0, res, 0, id);
        return new String(res);
        //      
        //      if(s==null || (s.indexOf('[')<0 && s.indexOf('{')<0)) return s;
        //      return s.substring(1,s.length()-1);      
    }
}