We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Parse & display text from .txt
Page Index Toggle Pages: 1
Parse & display text from .txt (Read 1558 times)
Parse & display text from .txt
Mar 19th, 2009, 1:47am
 
Hi,

I am trying to parse and display text from a .txt file. I have just begun. When I run the program it returns, "Cannot find a class or type named "GetResp"." I cannot figure out where the bug is. I am new to processing and programming so it is most likely a simple fix. Also, does anyone know of any examples that demonstrate how to parse and  display text from a .txt file? Thanks.

The current code:

PFont font;
String[] data;
GetResp resp;

void setup() {
 size(500,500);
 background(0, 70, 120);
 resp = new GetResp();
 font = loadFont("Serif-24.vlw");
 String[] data = loadStrings("c_p_c.txt");
 }
}

void draw() {
 resp.getRespo;
}

class GetResp {
 int start;
 int end;
 String respondents;
 
 GetResp() {
   for(int i = 0; i > data.length; i++) {
     int start = data[i].indexOf("'") + 4;
     int end = data[i].indexOf("'", start);
   }
 }
   
   void getRespo {
     for(int i = 0; i > data.length; i++) {
       String respondents = data[i].substring(start, end);
     }
   }
}

Re: Parse & display text from .txt
Reply #1 - Mar 19th, 2009, 8:58am
 
I noticed a useless '}' at the end of setup, and you have to add '()' after 'getRespo' in draw ('resp.getRespo()')and in the function declaration.

I can't run it because i have no text file but this is running :
Code:

PFont font;
String[] data;
GetResp resp;

void setup()
{
size(500,500);
background(0, 70, 120);
resp = new GetResp();
font = loadFont("Serif-24.vlw");
String[] data = loadStrings("c_p_c.txt");
}

void draw()
{
resp.getRespo();
}

class GetResp
{
int start;
int end;
String respondents;

GetResp()
{
for(int i = 0; i > data.length; i++)
{
int start = data[i].indexOf("'") + 4;
int end = data[i].indexOf("'", start);
}
}

void getRespo()
{
for(int i = 0; i > data.length; i++)
{
String respondents = data[i].substring(start, end);
}
}
}


and if you're going to parse a text file, maybe you want to look at the split() function : http://processing.org/reference/split_.html
Re: Parse & display text from .txt
Reply #2 - Mar 22nd, 2009, 3:11am
 
Thanks very much for the help.
Page Index Toggle Pages: 1