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 & HelpPrograms › Modifying a text file question.
Page Index Toggle Pages: 1
Modifying a text file question. (Read 549 times)
Modifying a text file question.
Oct 17th, 2006, 3:23pm
 
Hi. I want to be able to take a certain text file, which is basically a list of names and then have a program that will take off a certain piece of information from each line. Basically each line is a name followed by information in parenthesis, and I want to get rid of the information in the parenthesis. Im kind of just starting in Processing and haven't tried anything with text or other documents like this before. If anyone knows of the best way to go about doing this it'd be a great help. Thanks.
Re: Modifying a text file question.
Reply #1 - Oct 17th, 2006, 4:18pm
 
I think that the code below should do what you need.

Code:
String[] data;
data=loadStrings("MyFile.txt");

for(int i=0;i<data.length;i++)
{
int bracketPos=data[i].indexOf("(");
//finds the (

data[i]=data[i].substring(0,bracketPos-1);
// replace a line with just the first part of the line
}
saveStrings("MyEditedFile.txt",data);
Page Index Toggle Pages: 1