Here you can find the source of chopBraces(String s)
Parameter | Description |
---|---|
s | a parameter |
public static String chopBraces(String s)
//package com.java2s; //License from project: Open Source License public class Main { private final static String STRSQBRACKETSTART = "[", STRSQBRACKETEND = "]", STRCURLYSTART = "{", STRCURLYEND = "}", STRGT = ">", STRLT = "<"; /**//from www .j a v a 2 s . c o m * Removes '[' and ']' from beginning and end of a String, * but only if both are present. * @param s * @return */ public static String chopBraces(String s) { if (s.startsWith(STRSQBRACKETSTART) && s.endsWith(STRSQBRACKETEND)) return s.substring(1, s.length() - 1); // boolean changed; // do { // changed=true; // if(s.startsWith(STRSQBRACKETSTART)) s=s.substring(1); // else if(s.startsWith(STRCURLYSTART)) s=s.substring(1); // else if(s.startsWith(STRLT)) s=s.substring(1); // else if(s.endsWith(STRSQBRACKETEND)) s=s.substring(0,s.length()-1); // else if(s.endsWith(STRCURLYEND)) s=s.substring(0,s.length()-1); // else if(s.endsWith(STRGT)) s=s.substring(0,s.length()-1); // else changed=false; // } while(changed); return s; // // if(s==null || (s.indexOf('[')<0 && s.indexOf('{')<0)) return s; // return s.substring(1,s.length()-1); } }