We are about to switch to a new forum software. Until then we have removed the registration on this forum.
What should be the best solution to import a .txt to a (String?) array, where each line has 4 terms (or more) divided by comma (,), and then convert them inside the sketch into this scheme: {float, int, string, string}, where they could be accessed and referenced as numbers or strings?
I wouldn't need to convert the string ones, as it would be possible to search inside each String[] for such elements (by using equals() function), but how to reference the numbers on the same line? And I could refer to the int or float ones only by using int() e float() conversion functions (while pointing at its positions at the array), right?
The whole question is that I need to search strings inside the sketch that points out to the float and int numbers on the same line as the chosen string (to be used as parameters).
Another detail: I may need to create one array per .txt file (there are more than one).
.txt random example:
1.0, 5000, red, circle
1775.0, 15000, green, quad
3225.0, 6000, yellow, circle, left
Answers
float
&int
pair.Hello! Yes, sometimes there can be more than 2!
In fact, both of these terms are relevant, but only one is needed by time. The examples I gave were made in a generic way.
I'm working with the idea that each string is a TAG that I can use to reference each line of numbers, and each line of numbers has more than one tag, ok?
After, I will join randomly the lines that envolves the same tag (one of the strings per line).
Example: If I choose "red", I would get 2 numbers (one 'float' and one 'int') by line of each line that has "red" as a string element.
A better example of the .txt line (each string as an object of the same "kind").
1.0, 5000, red, green
1775.0, 15000, green, brown
3225.0, 6000, yellow, red, brown
GoToLoop, thanks for your attention and help! Yes, I only search for 1 "tag" at a time, and I want the pair of numbers associated w/it.
I don't have a deep knowledge about it, so I'm going to read this code and research how to interact with it using the data I have.
So you'd better read about HashMap:
https://processing.org/reference/HashMap.html
http://docs.oracle.com/javase/6/docs/api/java/util/Map.html
Ok, thanks for the links! Now I'm figuring out how to map the lines of the txt file.
Gonna need loadStrings() to read the files:
https://processing.org/reference/loadStrings_.html
And split() to extract each element from each line read:
https://processing.org/reference/split_.html
Oh yes! I'm already aware of these functions! I'm working on link the string data loaded from the txt file to the Map category.