How to read a String, char by char at a time
in
Programming Questions
•
1 years ago
Hi,
I'm sort of stuck on this. So I want to be able to read an ongoing live (twitter feeds) String, char by char and once it reads a char have it specifically do an action.
I have the parsing of the twitter String, but I'm stuck on reading each character individually and doing an action afterward. If someone could suggest anything, I'd really appreciate it! Thanks.
Here's my code:
I'm sort of stuck on this. So I want to be able to read an ongoing live (twitter feeds) String, char by char and once it reads a char have it specifically do an action.
I have the parsing of the twitter String, but I'm stuck on reading each character individually and doing an action afterward. If someone could suggest anything, I'd really appreciate it! Thanks.
Here's my code:
- PFont font;
String[] alphabet;
String[] strTweets;
String delimiters = " ,.?1;:";
float textX = width;
int counter = 0;
int index = 0;
int x = 0;
int nextPage = 0;
void setup() {
size(1024,288);
background(255,253,245);
font = createFont("Arial-Bold.vlw", 70);
textFont(font);
textAlign(LEFT);
ellipseMode(CENTER);
//Styles
imageMode(CENTER);
smooth();
//Tweets
fill(254,49,30);
textFont(font, 20);
//Search
XMLElement rss = new XMLElement(this,
"http://search.twitter.com/search.atom?q=search&show_user=true");
XMLElement tweets[] = rss.getChildren("entry/title");
strTweets= new String[tweets.length];
for(int i = 0; i < tweets.length; i++) {
strTweets[i] = tweets[i].getContent();
}
}
void draw() {
switch (nextPage) {
case 0://Splash Page
background(255,253,245);
tweet2char();
fill(202,236,245);
pushMatrix();
noStroke();
fill(202,236,245);
ellipse(beat(),20,150,150);
fill(253,215,181);
ellipse(1024,beat()+220,150,150);
stroke(0);
popMatrix();
break;
case 1://Interface/Tweets
background(255,253,245);
tweets();
pushMatrix();
noStroke();
fill(202,236,245);
ellipse(beat()+50,100,100,100);
fill(253,215,181);
ellipse(1024,beat()+75,50,50);
fill(255,216,209);
ellipse(1024,beat()+150,50,50);
fill(202,236,245);
ellipse(1024,beat()+225,50,50);
popMatrix();
break;
}
}
void tweets () {//Scroll Tweets
fill(254,49,30);
if(index < strTweets.length) {
text(strTweets[index], textX, 220);
textX = textX - 1.5;
float w = textWidth(strTweets[index]);
if(textX < -w) {
textX = width;
index = (index + 1) & strTweets.length;
}
}
}
void tweet2char() {
char[][] target;
target = new char[strTweets.length][];
for(int i = 0; i<strTweets.length;i++) {
target[i] = strTweets[i].toCharArray();
fill(0);
text(strTweets[i], textX, 220);
/**if(target = 'a') {
rect(50,50,50,50);
}*/
//String c1 = target.charAt(0);
//for(char c : target)
//println(c);
println("this is: " + i + "target: " + target);
//println("this is char: " + c1);
//println("this is: " + strTweets.charAt(i));
}
}
/*void test2char() {
char[] t = strTweets[i].toCharArray();
for(char c : t)
println(c);
println("The end!");
}*/
int beat() {
int beat = (int)(millis()/250.) % 5 + 1;
return beat;
}
void keyPressed() {
if(key == CODED) {
switch(keyCode) {
case UP:
case RIGHT:
nextPage++;
break;
case DOWN:
case LEFT:
nextPage--;
break;
}
}
if(nextPage > 2) nextPage = 0;
}
1