Results 1 to 3 of 3

Thread: Simple String Search

  1. #1
    Join Date
    Jul 2010
    Location
    Ny
    Beans
    6

    Talking Simple String Search

    I've been looking for a simple way to look up a String in a file that has a lot of words or Strings. There is a lot of examples out there, but wanted one without a lot of concatenation. I was just going to use a Scanner Object to open and then read the file using a while loop. Sorry if there is already one of these questions out there.

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Simple String Search

    what about the grep command in terminal? grep pattern file
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Jul 2010
    Location
    Ny
    Beans
    6

    Re: Simple String Search

    Sorry for the delaid response, i was going to respond but never did. Nevertheless, that is a good command and i wrote it down thinking it will be useful later when i'm looking for a file that installed and could not find. I should have let you all know that I was working in NetBeans and needed that JAVA code to write the while loop. When looking around on the net i found lots but was not what i needed. Again sy for the delay and this is what I found that worked well for what i was doing.

    double totalmpg = 0;
    double totalgas = 0; //setting values to 0
    double totalMisc = 0;
    while (salesLogSC.hasNext()) { // there is a Scanner here

    salesmanDate = salesLogSC.nextLine();
    name = salesLogSC.nextLine();
    salesmanMiles = salesLogSC.nextDouble();
    salesmanGas = salesLogSC.nextDouble();
    salesmanMisc = salesLogSC.nextDouble();
    endofInfo = salesLogSC.nextLine();
    salesLogSC.nextLine();
    /*Then i closed the file and worked with the data from the file*/

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •