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 › txt empty string removal
Page Index Toggle Pages: 1
txt empty string removal (Read 618 times)
txt empty string removal
Sep 1st, 2009, 1:57pm
 
  Hello again! I'm trying to make function to remove empty strings in txt file. It removes only 1 empty string between not empty strings.
And the thing I can't make is removal several empty strings successively - it doesn't want to see empty string in front of current "i" Here is the code:
Code:


String lines[] = loadStrings("loadsomefile.txt");
String[] neww = new String[lines.length];
String currentString = "";
String str1 = "";
String str2 = null;

for (int i = 0; i < lines.length-1; i++)
{
 currentString = lines[i];

 if(currentString.equals(str1) == true || currentString.equals(str2) == true  ) {
   currentString = lines[i] + lines[i+1];
   neww = append(neww,currentString);
 }
}
saveStrings("recordsomefile.txt",neww);


  I see that it recreates empty strings again, but I'm stumped  
  If you have some time, please take a look at the code above.
Re: txt empty string removal
Reply #1 - Sep 2nd, 2009, 6:48am
 
Code:
String lines[] = loadStrings("loadsomefile.txt");
String[] neww = new String[1]; // or [lines.length / 2] for example

for (int i = 0; i < lines.length; i++)
{
if (!lines[i].equals("")) {
neww = append(neww, lines[i]);
}
}
saveStrings("recordsomefile.txt",neww);
 
(Untested...)
Re: txt empty string removal
Reply #2 - Sep 2nd, 2009, 1:44pm
 
 It works great! Thank you very much PhiLho.  Roll Eyes
I've made everything complicated again  Undecided .
Page Index Toggle Pages: 1