vendredi 3 juillet 2015

Counting occurences of invisible ascii characters inside a character array?

Here's what I tried to do, I tried splitting my string args into a much smaller type- char array hoping I could capture that 'empty space' between the words.

Just 0, what did I do wrong? I made sure I included all the invisible characters based on the ascii table.. D:

String args is an argument passed btw.

public static void showInvisibleCharacters(String[] args) {

    String words = "";
    int invisibleOccurenceCount = 0;
    char[] seperatedWords = words.toCharArray();

    for (int counter = 0; counter < words.toCharArray().length - 1; counter++) {
        if (seperatedWords[counter] == (char) 9) {
            invisibleOccurenceCount++;
        } else if (seperatedWords[counter] == (char) 10) {
            invisibleOccurenceCount++;
        } else if (seperatedWords[counter] == (char) 13) {
            invisibleOccurenceCount++;
        } else if (seperatedWords[counter] == (char) 28) {
            invisibleOccurenceCount++;
        } else if (seperatedWords[counter] == (char) 29) {
            invisibleOccurenceCount++;
        } else if (seperatedWords[counter] == (char) 30) {
            invisibleOccurenceCount++;
        } else if (seperatedWords[counter] == (char) 31) {
            invisibleOccurenceCount++;
        } else if (seperatedWords[counter] == (char) 32) {
            invisibleOccurenceCount++;
        } else if (seperatedWords[counter] == (char) 160) {
            invisibleOccurenceCount++;
        }
    }
    System.out.println("Number of invisible occurences: "
            + invisibleOccurenceCount);

}




}<code>

Aucun commentaire:

Enregistrer un commentaire