Like Tree1Likes

Reading in fields of text from a .txt file.

This is a discussion on Reading in fields of text from a .txt file. within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by goldfish How do I deal with books whose names consist of multiple words(eg. "Song of Solomon" or ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,990
    Quote Originally Posted by goldfish
    How do I deal with books whose names consist of multiple words(eg. "Song of Solomon" or "I Kings")?
    Notice that there is whitespace after the book name and before the chapter number, right before the colon that separates chapter and verse numbers.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,744
    Yeah, I noticed that this morning. I haven't come up with a really good answer.

    If the book name was quoted or something -- "I Kings" -- it would be easy to parse.

    I think you will need a custom algorithm. You will have to scan the line for the location of the book name. Look for the first digit in the line; everything before that can be considered part of the book name. If you do this part by reading, as opposed to creating a substring, it may be easier since you have a stringstream.

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,990
    I don't think it is that hard. It should be possible to match with regex, e.g., "^(\.+?) (\d+):(\d+): " (PCRE, or something like that). If there is no match, then you should be dealing with a verse continuation. Otherwise, you search the list of books for the first match group to confirm, then convert the next two match groups to chapter and verse numbers, then go for the verse itself.
    whiteflags likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-05-2010, 02:43 PM
  2. Replies: 9
    Last Post: 12-08-2008, 09:27 AM
  3. Reading from text file
    By wiz23 in forum C++ Programming
    Replies: 6
    Last Post: 05-02-2005, 04:30 AM
  4. Cleaning all Text fields
    By publikum in forum C++ Programming
    Replies: 3
    Last Post: 01-14-2005, 11:46 PM
  5. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21