code: public static int countOccurrences(byte[] buff, int len, String word) {
  		int wordlen=word.length();
  		int end=len-wordlen;
  		int count=0;
  		Loop:
  		for(int c=0;c<=end;c++) {
  			for(int d=0;d<wordlen;d++) {
  				char ch1=(char)buff[c+d];
  				if(ch1<='Z' && ch1>='A') ch1+='a'-'A';
  				char ch2=word.charAt(d);
  				if(ch2<='Z' && ch2>='A') ch2+='a'-'A';
  				if(ch1!=ch2) continue Loop;
  			}
  			c+=wordlen-1;
  			count++;
  		}
  		return count;
  	}
docs: Counts how many times a word appears in a line.  Case insensitive matching.