Thread: Reading in fields of text from a .txt file.

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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, 10: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-15-2005, 12:46 AM
  5. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM