Java String Sanitize sanitize(final String s)

Here you can find the source of sanitize(final String s)

Description

Removes unprintable characters from the given string.

License

Open Source License

Declaration

public static String sanitize(final String s) 

Method Source Code

//package com.java2s;
// the Bio-Formats library, licensed according to Simplified BSD, as follows:

public class Main {
    /** Removes unprintable characters from the given string. */
    public static String sanitize(final String s) {
        if (s == null)
            return null;
        StringBuffer buf = new StringBuffer(s);
        for (int i = 0; i < buf.length(); i++) {
            final char c = buf.charAt(i);
            if (c != '\t' && c != '\n' && (c < ' ' || c > '~')) {
                buf = buf.deleteCharAt(i--);
            }//from ww  w.j a va  2s .  c o  m
        }
        return buf.toString();
    }
}

Related

  1. sanitize(char orig)
  2. sanitize(CharSequence string)
  3. sanitize(double[] outdata)
  4. sanitize(final String main)
  5. sanitize(final String name)
  6. sanitize(final String singleOctets, byte[] dest)
  7. sanitize(String input)
  8. sanitize(String input)
  9. sanitize(String input, String prohibitedStringsRegexp)