Java String Quote quote(String s)

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

Description

quote

License

CDDL license

Declaration

public static String quote(String s) 

Method Source Code

//package com.java2s;
//License from project: CDDL license 

public class Main {
    public static String quote(String s) {
        if (s.indexOf(' ') >= 0) {
            char dqc = '"', sqc = '\'';
            int len = s.length();
            if (s.charAt(0) == dqc && s.charAt(len - 1) == dqc)
                return s;
            if (s.charAt(0) == sqc && s.charAt(len - 1) == sqc)
                return s;
            String qs = (s.indexOf(dqc) >= 0) ? "'" : "\"";
            return qs + s + qs;
        } else//w  ww. j a  v a  2s.c  o  m
            return s;
    }
}

Related

  1. quote(String s)
  2. quote(String s)
  3. quote(String s)
  4. quote(String s)
  5. quote(String s)
  6. quote(String s)
  7. quote(String s)
  8. quote(String s)
  9. quote(String s, char ch)