0

Hi, Could some one point me in the right direction.

I'm trying to get a value thats in a file between tags.
for instance:

I'm reading an array out of a file per line
example:

myArray[0] = "<FILE_NAME>Testfile.dat</FILE_NAME>";

What i'm trying to do is to read every field in the array and search for the value between the predefined tags.

what will be the most efficient way to do this?

Thanks in advanced.
Nick

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Nicklorion
1

There are probably several ways to do it, but I would use the string search feature of std::string class

std::string line = "<FILE_NAME>Testfile.dat</FILE_NAME>";
std::string filename;
size_t pos;

if( (pos = line.find("<FILE_NAME>") > string::npos)
{
    filename = line.substr(pos+11);
    // truncate the </FILE_NAME> tag
    pos = filename.find('<'); 
    filename = filename.substr(0, pos);
}
Votes + Comments
Very Nice
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.