Java String Chop chopBraces(String s)

Here you can find the source of chopBraces(String s)

Description

Removes '[' and ']' from beginning and end of a String, but only if both are present.

License

Open Source License

Parameter

Parameter Description
s a parameter

Declaration

public static String chopBraces(String s) 

Method Source Code

//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);      
    }
}

Related

  1. chop(String[] arr, int pos)
  2. chop(StringBuffer buffer, int chars)
  3. chopAccelerator(final String title)
  4. ChopAllLf(String this_string, String chomp_off)
  5. ChopAllRt(String this_string, String chomp_off)
  6. chopCommentFromArgs(String[] args)
  7. chopExt(String orig)
  8. chopFirstComponent(String s)
  9. chopFractionalPart(float original, int no_of_digits )