Java String Single Quote singleQuotedString(String str)

Here you can find the source of singleQuotedString(String str)

Description

single Quoted String

License

Open Source License

Declaration

public static String singleQuotedString(String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String singleQuotedString(String str) {
        StringBuilder result = new StringBuilder("'");
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if (ch == '\n') {
                result.append("\\n");
                continue;
            }/*from w  ww .  j  av  a2 s . c o  m*/
            if (ch == '\r') {
                result.append("\\r");
                continue;
            }
            if (ch == '\t') {
                result.append("\\t");
                continue;
            }
            if (ch == '\'' || ch == '\\')
                result.append('\\');
            result.append(ch);
        }
        result.append("'");
        return result.toString();
    }
}

Related

  1. singleQuote(Object thing)
  2. singleQuote(String data)
  3. singleQuote(String input)
  4. singleQuote(String s)
  5. singleQuote(String text)
  6. singleQuoteForSql(String val)
  7. singleQuotize(String s)
  8. singleUnquoted(String string)