Java Unix Date escapeUnixChar(String strToEscape)

Here you can find the source of escapeUnixChar(String strToEscape)

Description

escape Unix Char

License

Apache License

Declaration

public static String escapeUnixChar(String strToEscape) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.StringCharacterIterator;

public class Main {
    public static String escapeUnixChar(String strToEscape) {
        StringCharacterIterator charIter = new StringCharacterIterator(
                strToEscape);//from  w  ww . ja v  a 2  s . c om
        StringBuilder buf = new StringBuilder();
        char ch = charIter.current();
        while (ch != 65535) {
            if (ch == ';')
                buf.append("\\;");
            else if (ch == '&')
                buf.append("\\&");
            else if (ch == '(')
                buf.append("\\(");
            else if (ch == ')')
                buf.append("\\)");
            else if (ch == '|')
                buf.append("\\|");
            else if (ch == '*')
                buf.append("\\*");
            else if (ch == '?')
                buf.append("\\?");
            else if (ch == '[')
                buf.append("\\[");
            else if (ch == ']')
                buf.append("\\]");
            else if (ch == '~')
                buf.append("\\~");
            else if (ch == '{')
                buf.append("\\{");
            else if (ch == '}')
                buf.append("\\}");
            else if (ch == '>')
                buf.append("\\>");
            else if (ch == '<')
                buf.append("\\<");
            else if (ch == '^')
                buf.append("\\^");
            else if (ch == '"')
                buf.append("\\\"");
            else if (ch == '$')
                buf.append("\\$");
            else
                buf.append(ch);
            ch = charIter.next();
        }
        return buf.toString();
    }
}

Related

  1. getDispTimeByUnixTime(long unixSec)
  2. getUnixDate()
  3. getUnixDate(Date date)
  4. getUnixDate(long millis)