Notice that there is whitespace after the book name and before the chapter number, right before the colon that separates chapter and verse numbers.Originally Posted by goldfish
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 ...
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.
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.