how many times a word appears into a txt file

Posted by m4g4bu on Stack Overflow See other posts from Stack Overflow or by m4g4bu
Published on 2012-06-30T21:10:24Z Indexed on 2012/06/30 21:15 UTC
Read the original article Hit count: 250

Filed under:
|

I've a problem when i tried to count how many time a word appears into a txt file.

1/ I create a textfield ( txta ) 2/ I create a button to apply the action ( btn ) 3/ I create a textarea ( area ) that is the place where the content of the file is displayed

When I select the file, the content of the file is displayed on area, then I enter the word in txta to search and then I clicked the btn but the code is not working

public int contarPalabras(String chain, String word) {

        // Recibe un string y una palabra y devuelve la cantidad de veces que encontrĂ³ esa palabra en el string.
        // Si no encuentra la letra devuelve (-1).


         int cant = 0;
         int intIndex = chain.indexOf(word);

         if(intIndex == - 1){
            cant = -1;
        }else{
            cant = intIndex;
        }

        return cant;
    }

© Stack Overflow or respective owner

Related posts about java

Related posts about string