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

**URL:** <https://discourse.processing.org/t/find-number-in-a-text-and-return-string-from-the-row-below/16670>\
**Category:** Coding Questions\
**Created:** [December 28, 2019, 3:43am UTC](https://discourse.processing.org/t/find-number-in-a-text-and-return-string-from-the-row-below/16670 "2019-12-28T03:43:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![molo32](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@molo32](https://discourse.processing.org/u/molo32)\
**Post date:** [December 28, 2019, 3:43am UTC](https://discourse.processing.org/t/find-number-in-a-text-and-return-string-from-the-row-below/16670/1 "2019-12-28T03:43:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 28, 2019, 3:52am UTC](https://discourse.processing.org/t/find-number-in-a-text-and-return-string-from-the-row-below/16670/2 "2019-12-28T03:52:11Z")

</div>

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

compare a string pls. use  
[https://processing.org/reference/String\_equals\_.html](https://processing.org/reference/String_equals_.html)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 28, 2019, 4:28am UTC](https://discourse.processing.org/t/find-number-in-a-text-and-return-string-from-the-row-below/16670/3 "2019-12-28T04:28:53Z")

</div>

why double post?

i see a problem:

```auto
"BANANA, APPLE, GRAPE"

```

is very different from

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

```

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

so, you have

- a array to check or

- String you need to split first ?  
[https://processing.org/reference/split\_.html](https://processing.org/reference/split_.html)  
[https://processing.org/reference/splitTokens\_.html](https://processing.org/reference/splitTokens_.html)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 28, 2019, 7:30am UTC](https://discourse.processing.org/t/find-number-in-a-text-and-return-string-from-the-row-below/16670/4 "2019-12-28T07:30:09Z")

</div>

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: [https://www.processing.org/reference/HashMap.html](https://www.processing.org/reference/HashMap.html)

Chrisir

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 28, 2019, 1:03pm UTC](https://discourse.processing.org/t/find-number-in-a-text-and-return-string-from-the-row-below/16670/5 "2019-12-28T13:03:00Z")

</div>

example using two arrays

```auto
String[]
  line1 = { "1000", "55", "123"};
String[]  
  line2 = { "hello", "bye", "good" };

String search = "55";

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

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

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

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

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

  //search 

  // index 
  int idx = 0;

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

    idx++;
  }

  // none found 
  return -1;
}//func 
//

```
