Java String Dequote dequote(String s)

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

Description

dequote

License

Open Source License

Declaration

public static String dequote(String s) 

Method Source Code

//package com.java2s;

public class Main {
    public static String dequote(String s) {
        return dequote(s, new char[] { '"', '\'' });
    }/*from w ww .  j av  a  2s .co  m*/

    public static String dequote(String s, char[] quoteChars) {
        String result = s;
        if (indexOfAnyOf(s, quoteChars) == 0) {
            final char leading = s.charAt(0);
            if (s.charAt(s.length() - 1) == leading) {
                result = s.substring(1, s.length() - 1);
            }
        }
        return result;
    }

    public static int indexOfAnyOf(String s, char[] chars) {
        return indexOfAnyOf(s, chars, 0);
    }

    public static int indexOfAnyOf(String s, char[] chars, int fromIndex) {
        int result = -1;
        for (int i = fromIndex; i < s.length() && result == -1; i++) {
            final int one = isOneOf(s.charAt(i), chars);
            if (-1 != one) {
                result = i;
            }
        }
        return result;
    }

    public static int isOneOf(char c, char[] set) {
        int result = -1;
        for (result = 0; result < set.length && c != set[result]; result++) {
        }
        return result >= set.length ? -1 : result;
    }
}

Related

  1. dequote(final String in)
  2. deQuote(String in)
  3. dequote(String inputString)
  4. deQuote(String quotedString)
  5. deQuote(String s)
  6. dequote(String str)
  7. dequote(String str)
  8. dequote(String str)
  9. dequote(String str, char quote)