Note that there are some explanatory texts on larger screens.

plurals
  1. POSearching for exact match is returning substrings.
    text
    copied!<p>I have a small java program that searches the contents of all *.txt files in a folder for a specific string.</p> <p>Example of my problem:</p> <ol> <li>Enter string to find:</li> <li>Enter string to find: 6570</li> <li>Enter string to find: 6570<br> Found 2 time(s) in kyle.txt!<br> Found 2 time(s) in kylezz.txt!<br> Press any key to continue . . .</li> </ol> <hr> <p>The problem:</p> <p>It is searching for 6570 however I pickup results for values like this with that string:</p> <pre> 11111116570111111 657011111 111116570 6570 </pre> <hr> <p>Question: I want to search for only an exact string, eg:"6570". how can I make it return <strong>only</strong> the exact value of 6570? I do not want any extra characters at the beginning or end, only the exact value.</p> <p>Here is my code:</p> <pre><code>import java.io.*; import java.util.*; public class FileScanner { public static void main(String args[]) { System.out.print("Enter string to find: "); Scanner sc = new Scanner(System.in); find(sc.nextLine()); } public static void find(String delim) { File dir = new File("files"); if (dir.exists()) { String read; try { File files[] = dir.listFiles(); for (int i = 0; i &lt; files.length; i++) { File loaded = files[i]; if (loaded.getName().endsWith(".txt")) { BufferedReader in = new BufferedReader(new FileReader( loaded)); StringBuffer load = new StringBuffer(); while ((read = in.readLine()) != null) { load.append(read + "\n"); } String delimiter[] = new String(load).split(delim); if (delimiter.length &gt; 1) { System.out.println("Found " + (delimiter.length - 1) + " time(s) in " + loaded.getName() + "!"); } } } } catch (Exception e) { e.printStackTrace(); } } else { System.out.println("error: dir wasn't found!"); } } } </code></pre> <p>Thanks guys I really hope you can help me with my programming problem. I've been trying to fix it for about a month now and now I'm asking for help.</p>
 

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