We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there, it seems to me, that the function loadStrings does not like to read String-variables. I have an array with filenames and want to tell loadStrings to load each file one after another. Like this:
for (int i = 0; i < filenames.length; i++) { texts[i] = loadStrings(filenames[i]); }
I would like to access and process many text files one after another. But how?
Thanks in advance!
Adrian
Answers
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
You can use join() in order to convert loadStrings()'s String[] to String:
for (int i = 0; i < filenames.length; ++i) texts[i] = join(loadStrings(filenames[i]), ENTER);
Or you can have texts declared as a 2D array instead: ;;)
Thank you! I tried the 2D array, but must have failed in declaring it correctly, now that I see your code. On the other hand I would only get lost in dimensions, so I'd rather stick to the first solution join(). Thanks again! Cheers, A
But somehow it does not work...
@AdrainG -- re:
You need to share a minimal example of what your code does to "process" your text files. Otherwise there is no way for forum members to guess what "it does not work" means -- we can't read your mind. Give a simple code examle; give the error message you are getting.
Hi Jeremy, sorry, you are right.
My attempt was this: I have a file which contains a list of text files. So first I open the File-List, and then I use loadStrings in a for loop to open every single text. Let's put the case, that I want to open one after another and look what's on line 13, then save the line and store it into another textfile.
I got this working so far:
String[] files; String[] texts;
files = loadStrings("fileList.lst"); printArray(files);
texts = new String[files.length];
for (int i = 0; i < files.length; i++) {
println(files[i]); texts[i] = join(loadStrings(files[i]), ENTER);
}
Now how do I get to line 13 of every text, I have to split up every part of the texts-Array or I make the Array twodimensional, which is not working.
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
It seems, as if loadStrings does only accept String-Parameters, so now this code works: