Find number in a text and return string from the row below

for example I have a text that contains 2 lines
1- “1000”, “55”, “123”
2- “hello”, “bye”, “good”

I want a function that does this

foo (“55”)

this would have to find me the string “55” and return what is in the row below, in this case “bye”

How do I do this without using Table?

1 Like

please post the code you have so far
( like reading ?file? … store to variables… ? string ? array? )

compare a string pls. use

why double post?

i see a problem:


is very different from

“1000”, “55”, “123”
“hello”, “bye”, “good”

and that would make the function you want to write also very different.

so, you have

1 Like

Yeah, when you have an array of String (many lines), for loop over it (your y or line number)

Then use split inside the for loop (when each line is like “banana, apple, straw”)

And inside the 1st for loop another for loop to loop over the parts of the line (your x or parts number)

Use .equals() to check for equality

If you have a match, store y+1 (if smaller than number of lines) and x

And use this

Look up data

When you need to look up data, also see HashMap:


example using two arrays

  line1 =  { "1000", "55", "123"};
  line2 = { "hello", "bye", "good" };

String  search = "55";

// ------------------------------------------------------------------------------------

void setup() {
  size(650, 650);

  int idx = wordIndexSearch(line1, search);
  println(idx); // result
  if (idx>-1)
    text(line2[idx], 111, 111);

// ---------------------------------------------------------------------------

int wordIndexSearch( String[] words, 
  String word) {


  // index 
  int idx = 0;

  for (String w : words) {
    if (word.equals(w)) {  
      return idx;


  // none found 
  return -1;
1 Like