Java String Remove removeEscape(String s_)

Here you can find the source of removeEscape(String s_)

Description

remove Escape

License

Open Source License

Declaration

public static String removeEscape(String s_) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    public static String removeEscape(String s_) {
        if (s_ == null)
            return null;

        StringBuffer sb_ = new StringBuffer();
        int i = 0;
        while (true) {
            int j = s_.indexOf('\\', i);
            if (j >= 0) {
                sb_.append(s_.substring(i, j));
                i = j + 1;/*w ww  . ja v  a2 s .c  om*/
                if (i < s_.length() - 1 && s_.charAt(i) == '\\')
                    i++;
            } else
                break;
        }
        if (sb_.length() == 0)
            return s_;
        return i >= 0 ? sb_ + s_.substring(i) : sb_.toString();
    }

    /**
     * Format a double number.
     * @param  f  # of digits in fraction
     */
    public static String toString(double d, int f) {
        return toString(d, -1, f);
    }

    /**
     * Format a double number.
     * @param  n  length of result
     * @param  f  # of digits in fraction
     */
    public static String toString(double d, int nn, int ff) {
        String r_ = d + "";
        int ii_ = r_.indexOf(".");
        String head_ = null, tail_ = null;

        if (ii_ < 0) {
            head_ = r_;
            tail_ = "";
        } else {
            head_ = r_.substring(0, ii_);
            tail_ = r_.substring(ii_ + 1);
        }

        int dot = ff > 0 ? 1 : 0;

        if (nn < 0)
            nn = head_.length() + dot + ff;

        if (head_.length() > nn)
            return head_;
        else if (head_.length() + ff + dot < nn) // prepends " " to head_
        {
            StringBuffer sb_ = new StringBuffer(nn - ff - dot - head_.length());
            for (int i = 0; i < sb_.capacity(); i++)
                sb_.append(' ');
            head_ = sb_ + head_;
        }

        if (ff == 0)
            return head_;

        if (tail_.length() > ff) // truncate tail_
        {
            tail_ = tail_.substring(0, ff);
        } else // appends "0" to tail_
        {
            StringBuffer sb_ = new StringBuffer(ff - tail_.length());
            for (int i = 0; i < sb_.capacity(); i++)
                sb_.append('0');
            tail_ += sb_.toString();
        }

        return head_ + "." + tail_;
        /*
        if (d == 0) return "0";
            
        double ten = Math.exp(Math.log(10)*ff);
        String sign = "";
        if (d < 0) { d = -d;  sign = "-"; }
            
        //System.out.println("double = " + d);
        //System.out.println("  sign = " + sign);
        //System.out.println("   ten = " + ten);
            
        if (d >= 1) 
        {
          long v = (long) (d*ten) / (long)ten;
          long f = (long) (d*ten) % (long)ten;
            
          return sign + v + "." + f;
        }
        else
        {
          double log = Math.log(d)/Math.log(10);
          int e = (int)log;
          if (log - e < 0) e--;
          log -= e;
          double fraction = Math.exp(Math.log(10)*log);
            
          //System.out.println("        log = " + log);
          //System.out.println("   fraction = " + fraction);
          //System.out.println("exponential = " + e);
          return sign + toString(fraction, n) + 
        (e==0? "": "e" + (e>0? "+":"") + e);
        }
        */
    }

    public static String toString(Hashtable ht_) {
        StringBuffer sb_ = new StringBuffer();
        Enumeration keys_ = ht_.keys(), elements_ = ht_.elements();
        while (keys_.hasMoreElements()) {
            sb_.append(toString(keys_.nextElement()) + ": " + toString(elements_.nextElement()) + "\n");
        }
        return sb_.toString();
    }

    public static String toString(Object o_) {
        return toString(o_, ",", 10);
    }

    public static String toString(Object o_, String separator_, int maxcount_) {
        if (o_ instanceof long[])
            return toString((long[]) o_, separator_, maxcount_);
        if (o_ instanceof int[])
            return toString((int[]) o_, separator_, maxcount_);
        if (o_ instanceof boolean[])
            return toString((boolean[]) o_, separator_, maxcount_);
        if (o_ instanceof double[])
            return toString((double[]) o_, separator_, maxcount_);
        if (o_ instanceof float[])
            return toString((float[]) o_, separator_, maxcount_);
        if (o_ instanceof byte[])
            return toString((byte[]) o_, separator_, maxcount_);
        if (o_ instanceof char[])
            return toString((char[]) o_, separator_, maxcount_);
        if (o_ == null)
            return "<null>";
        if (!(o_ instanceof Object[]))
            return o_.toString();
        Object[] a_ = (Object[]) o_;
        if (a_.length == 0)
            return "Object[0]";
        StringBuffer sb_ = new StringBuffer("(" + toString(a_[0]));
        maxcount_ = Math.min(maxcount_, a_.length);
        for (int i = 1; i < maxcount_; i++)
            sb_.append(separator_ + toString(a_[i]));
        if (a_.length > maxcount_)
            sb_.append(separator_ + "...");
        sb_.append(")");
        return sb_.toString();
    }

    public static String toString(double[] a_) {
        return toString(a_, ",", 10);
    }

    public static String toString(double[] a_, String separator_, int maxcount_) {
        if (a_ == null)
            return "<null_double[]>";
        if (a_.length == 0)
            return "double[0]";
        StringBuffer sb_ = new StringBuffer("(" + a_[0]);
        maxcount_ = Math.min(maxcount_, a_.length);
        for (int i = 1; i < maxcount_; i++)
            sb_.append(separator_ + a_[i]);
        if (a_.length > maxcount_)
            sb_.append(separator_ + "...");
        sb_.append(")");
        return sb_.toString();
    }

    public static String toString(float[] a_) {
        return toString(a_, ",", 10);
    }

    public static String toString(float[] a_, String separator_, int maxcount_) {
        if (a_ == null)
            return "<null_float[]>";
        if (a_.length == 0)
            return "float[0]";
        StringBuffer sb_ = new StringBuffer("(" + a_[0]);
        maxcount_ = Math.min(maxcount_, a_.length);
        for (int i = 1; i < maxcount_; i++)
            sb_.append(separator_ + a_[i]);
        if (a_.length > maxcount_)
            sb_.append(separator_ + "...");
        sb_.append(")");
        return sb_.toString();
    }

    public static String toString(long[] a_) {
        return toString(a_, ",", 10);
    }

    public static String toString(long[] a_, String separator_, int maxcount_) {
        if (a_ == null)
            return "<null_long[]>";
        if (a_.length == 0)
            return "long[0]";
        StringBuffer sb_ = new StringBuffer("(" + a_[0]);
        for (int i = 1; i < a_.length; i++)
            sb_.append(separator_ + a_[i]);
        if (a_.length > maxcount_)
            sb_.append(separator_ + "...");
        sb_.append(")");
        return sb_.toString();
    }

    public static String toString(int[] a_) {
        return toString(a_, ",", 10);
    }

    public static String toString(int[] a_, String separator_, int maxcount_) {
        if (a_ == null)
            return "<null_int[]>";
        if (a_.length == 0)
            return "int[0]";
        StringBuffer sb_ = new StringBuffer("(" + a_[0]);
        maxcount_ = Math.min(maxcount_, a_.length);
        for (int i = 1; i < maxcount_; i++)
            sb_.append(separator_ + a_[i]);
        if (a_.length > maxcount_)
            sb_.append(separator_ + "...");
        sb_.append(")");
        return sb_.toString();
    }

    public static String toString(boolean[] a_) {
        return toString(a_, ",", 10);
    }

    public static String toString(boolean[] a_, String separator_, int maxcount_) {
        if (a_ == null)
            return "<null_boolean[]>";
        if (a_.length == 0)
            return "boolean[0]";
        StringBuffer sb_ = new StringBuffer("(" + a_[0]);
        maxcount_ = Math.min(maxcount_, a_.length);
        for (int i = 1; i < maxcount_; i++)
            sb_.append(separator_ + a_[i]);
        if (a_.length > maxcount_)
            sb_.append(separator_ + "...");
        sb_.append(")");
        return sb_.toString();
    }

    public static String toString(byte[] a_) {
        return toString(a_, ",", 10);
    }

    public static String toString(byte[] a_, String separator_, int maxcount_) {
        if (a_ == null)
            return "<null_byte[]>";
        if (a_.length == 0)
            return "byte[0]";
        StringBuffer sb_ = new StringBuffer("(" + ((int) a_[0] & 0x0FF));
        maxcount_ = Math.min(maxcount_, a_.length);
        for (int i = 1; i < maxcount_; i++)
            sb_.append(separator_ + ((int) a_[i] & 0x0FF));
        if (a_.length > maxcount_)
            sb_.append(separator_ + "...");
        sb_.append(")");
        return sb_.toString();
    }

    public static String toString(char[] a_) {
        return toString(a_, ",", 10);
    }

    public static String toString(char[] a_, String separator_, int maxcount_) {
        if (a_ == null)
            return "<null_char[]>";
        if (a_.length == 0)
            return "char[0]";
        StringBuffer sb_ = new StringBuffer("(" + ((int) a_[0] & 0x0FFFF));
        maxcount_ = Math.min(maxcount_, a_.length);
        for (int i = 1; i < maxcount_; i++)
            sb_.append(separator_ + ((int) a_[i] & 0x0FFFF));
        if (a_.length > maxcount_)
            sb_.append(separator_ + "...");
        sb_.append(")");
        return sb_.toString();
    }

    public static String toString(Class class_) {
        if (class_ == int[].class)
            return "int[]";
        else if (class_ == double[].class)
            return "double[]";
        else if (class_ == long[].class)
            return "long[]";
        else if (class_ == boolean[].class)
            return "boolean[]";
        else if (class_ == byte[].class)
            return "byte[]";
        else if (class_ == float[].class)
            return "float[]";
        else
            return class_.getName();
    }
}

Related

  1. removeAll(String targetStr, String removeStr)
  2. removeAndConcatenateAlternate(String s1, String s2)
  3. removeBlankLines(String s)
  4. removeCommandFromString(String commandString)
  5. removeEmpties(final String... values)
  6. removeExtraSpacesAndSpecialCharacters(String toSearch, boolean setAllToLowerCase)
  7. removeField(BSONObject b, String fieldName)
  8. removeFillers(String str)
  9. removeFromSearchPath(String _path)