Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your record format is simple enough that I'd just use String's <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#split%28java.lang.String%29" rel="nofollow noreferrer">split</a> method to get the date and time. As pointed out in the comments, having names that can contain spaces complicates things just enough that splitting the record by spaces won't work for every field. I used a regular expression to grab the other three pieces of information.</p> <pre><code>public static void main(String[] args) { String record1 = "12/18/2009 02:08:26 Admitted Doe, John (Card #111) at South Lobby [In]"; String record2 = "12/18/2009 02:08:26 Admitted Van Halen, Eddie (Card #222) at South Lobby [In]"; String record3 = "12/18/2009 02:08:26 Admitted Thoreau, Henry David (Card #333) at South Lobby [In]"; summary(record1); summary(record2); summary(record3); } public static void summary(String record) { String[] tokens = record.split(" "); String date = tokens[0]; String time = tokens[1]; String regEx = "Admitted (.*), (.*) \\(Card #(.*)\\)"; Pattern pattern = Pattern.compile(regEx); Matcher matcher = pattern.matcher(record); matcher.find(); String lastName = matcher.group(1); String firstName = matcher.group(2); String cardNumber = matcher.group(3); System.out.println("\nDate: " + date); System.out.println("Time: " + time); System.out.println("First Name: " + firstName); System.out.println("Last Name: " + lastName); System.out.println("Card Number: " + cardNumber); } </code></pre> <p>The regular expression <code>"Admitted (.*), (.*) \\(Card #(.*)\\)"</code> uses grouping parentheses to store the information you're trying to extract. The parentheses that exist in your record must be escaped.</p> <p>Running the code above gives me the following output:</p> <pre><code>Date: 12/18/2009 Time: 02:08:26 First Name: John Last Name: Doe Card Number: 111 Date: 12/18/2009 Time: 02:08:26 First Name: Eddie Last Name: Van Halen Card Number: 222 Date: 12/18/2009 Time: 02:08:26 First Name: Henry David Last Name: Thoreau Card Number: 333 </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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