Filter a word from an string array
in
Programming Questions
•
1 years ago
Hey!
I am trying to filter my array ( which is a RSS feed, which is getting updated every five seconds) for a keyword "bieber".
I've managed to get the rss feed going, which you will see if you run the program. But I don't know how to filter out the word "bieber" (which occurs occasionally).
Also, when the word "bieber" occurs I want it to be saved in a "int bieberHate =++", that counts everytime the word is being spoken of.
Im glad for any hints!
- import simpleML.*;
- XMLRequest xmlRequest;
- int startTime; // for the timer to make request ever N seconds
- int bieberHate; // declare a varible for each time Bieber is spoken of.
- void setup() {
- size(200, 200);
- // Creating and starting the request
- xmlRequest = new XMLRequest(this, "http://www.search.twitter.com/search.rss?q=love");
- xmlRequest.makeRequest();
- }
- void draw() {
- background(0);
- // Every 5 seconds, make a new request
- int now = millis();
- if (now - startTime > 5000) {
- xmlRequest.makeRequest();
- println("Making request!");
- startTime = now;
- }
- }
- // When the request is complete
- void netEvent(XMLRequest ml) {
- // Retrieving an array of all XML elements inside "<title*>" tags
- String[] tweets = ml.getElementArray("title");
- for (int i = 0; i < tweets.length; i++) {
- println(tweets[i]);
- }
- //filter my array, only displaying if the string contains the word "bieber", and if it does, it should increase the value of my int bieberHate by 1.
- }
1