Indicates whether a character is an XML whitespace. - Android XML

Android examples for XML:XML String

Description

Indicates whether a character is an XML whitespace.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        char c = 'a';
        System.out.println(isWhitespace(c));
    }//from w w w. j  av a2s  . c  o m

    /**
     * Indicates whether a character is an XML whitespace.
     *
     * @param c
     *            The character.
     * @return <tt>true</tt> if the character is an XML whitespace,
     *         <tt>false</tt> otherwise.
     */
    public static boolean isWhitespace(char c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t';
    }

    /**
     * Indicates whether a character sequence is an XML whitespace.
     *
     * @param ch
     *            The char sequence.
     * @param start
     *            The start position.
     * @param length
     *            The end position.
     * @return <tt>true</tt> if the character sequence contains only XML
     *         whitespaces, <tt>false</tt> otherwise.
     */
    public static boolean isWhitespace(char[] ch, int start, int length) {
        for (int i = start; i < start + length; i++) {
            char c = ch[i];
            if (c != '\n' && c != '\t' && c != '\r' && c != ' ') {
                return false;
            }
        }
        return true;
    }
}

Related Tutorials