Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Comparing String Input On A Textfile Content
    primarykey
    data
    text
    <p>May I ask you to guide me how I can accomplish this problem? I need to compare an inputWord to a string inside a .txt file and if found, return the whole line but if not, show "word not found".</p> <p>Example:</p> <pre><code>inputWord: abacus Text file content: abaca - n. large herbaceous Asian plant of the banana family. aback - adv. archaic towards or situated to the rear. abacus - n. a frame with rows of wires or grooves along which beads are slid, used for calculating. ... so on Returns: abacus with its definition </code></pre> <p>What i am trying to do is compare my inputWord to the words before the " - " (hyphen as delimiter), if they dont match, move to the next line. If they match, copy the whole line.</p> <p>I hope it doesnt seem like im asking you to "do my homework" but I tried tutorials around different forums and sites. I also read java docs but i really cannot put them together to accomplish this.</p> <p>Thank you in advance!</p> <p>UPDATE:</p> <p>Here's my current code:</p> <pre><code>if(enhancedStem.startsWith("a")) { InputStream inputStream = getResources().openRawResource(R.raw.definitiona); try { BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); String s = in.readLine(); String delimiter = " - "; String del[]; while(s != null) { s = in.readLine(); del = s.split(delimiter); if (enhancedStem.equals(del[0])) { in.close(); databaseOutput.setText(s); break; } } in.close(); } catch (FileNotFoundException e) { databaseOutput.setText("" + e); } catch (IOException e1) { databaseOutput.setText("" + e1); } } </code></pre> <p>Thanks a lot! Here's what I came up, and it returns the definition of inputs properly but the problem is, when i enter a word not found in the textfile, the app crashes. The catch phrase doesn't seem to work. Have any idea how I can trap it? Logcat says NullPointerExcepetion at line 4342 which is</p> <pre><code>s = in.readLine(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload