Hello everyone,

I downloaded the source of an internet file and need to filter a specific part of it.

I know how the string::size_type position = Line.find("World:</TD><TD>"); function works, but this only tells me where the data I am looking for is located (the data is after "World:</TD><TD>").

I want to have everything that is behind it in a different string, until the "<" gets reached.

Example:

</TR><TR BGCOLOR=#F1E0C6><TD>World:</TD><TD>Blahblah</TD></TR>

is loaded into my string "Line".
I run my sorting thing and it should return "Blahblah" in an other string.

It is an std::string type variable.

I am also looking for a way to convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const
char *'

(at least, the error message says so, it is just a string to const char* conversion)


Thanks in advance.
Eddy

Is this anything like you're trying to do?

#include <iostream>
#include <string>
using namespace std;

bool foo(string &result, const string &Line)
{
   static const string keystart("World:</TD><TD>"), keyend("</TD></TR>");
   string::size_type start = Line.find(keystart);
   if ( start != string::npos )
   {
      start += keystart.length();
      string::size_type end = Line.find(keyend, start);
      if ( end != string::npos )
      {
         result = Line.substr(start, end - start);
         return true;
      }
   }
   return false;
}

int main()
{
   string Line("</TR><TR BGCOLOR=#F1E0C6><TD>World:</TD><TD>Blahblah</TD></TR>");
   string text;
   if ( foo(text, Line) )
   {
      cout << text << '\n';
   }
   return 0;
}

/* my output
Blahblah
*/

EDIT:
I did it. String to const char* conversion can be done with string.c_str() Thanks for your help Dave! I really appreciate it

Mwah... Looking pretty good... I'll try it.

Thanks for your reply.

I'm still having problems converting a string to a const char*.


Thanks again,
Eddy
This question has already been answered. Start a new discussion instead.