void CRobotDlg::OnBnClickedSnip()
{
//---------- navigate to Snip
CString sUrlSnip= L"http://Snip";
m_ctlBrowser.Navigate(sUrlSnip, 0,0,0,0);
while (m_ctlBrowser.get_ReadyState() != READYSTATE_COMPLETE) {
DelayMs( 100 );
}
//------ page is ready to process
IHTMLDocument2* pDoc= (IHTMLDocument2*)m_ctlBrowser.get_Document();
IHTMLElement* pElemBody= NULL;
pDoc->get_body(&pElemBody);
CComBSTR bstrHTML;
pElemBody->get_innerHTML(&bstrHTML);
CString sBody= bstrHTML; // easier to work with as a CString
//MessageBox(sBody); // debug, shows the string as a message
//----------------- zero-in on the data of interest
int nOffset= sBody.Find(L"last href");
CString sTmp= sBody.Mid(nOffset); // lop off the preceding HTML
//MessageBox(sTmp); // debug, shows the string as a message
int nStart= sTmp.Find(L"Snip")+N; // isolate last page number
int nEnd= sTmp.Find(L"Snip")-N;
CString sLastPageNumber= sTmp.Mid(nStart, nEnd-nStart);
//MessageBox(sTmp); // debug, shows the string as a message
MessageBox(sLastPageNumber); // debug, shows the most recently assigned data
}
Hello, I have used this code to successfully harvest a string holding some data I need (a number, going to be the iterator in a for loop). I now need to convert this string, which is definately holding an integer.
I have hit a brick wall so to speak, I will detail what i've tried, all either breaking my program, or refusing to compile.
CStringA sLastPageNumber= sTmp.Mid(nStart, nEnd-nStart);
This would work, but it would mean going all the way back up the method, replacing CString with CStringA, which doesnt work with stuff like "&bstrHTML". I just tried this after I saw CStringA on some barely related post I rolled into. I have no idea what the differences are.
// Convert a TCHAR string to a LPCSTR
CT2CA ConvertedLastPageNumber (LastPageNumber);
// construct a std::string using the LPCSTR input
std::string strStd (ConvertedLastPageNumber);
This would work if my compiler wasnt throwing these errors;
error C2039: 'string' : is not a member of 'std'
error C2065: 'string' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'strStd'
error C3861: 'strStd': identifier not found
Ref for this solution
CString s = "123";
int x = atoi( s );
Annoyingly, this implies it should work right out of the box, it throws this error message though; error C2664: 'atoi' : cannot convert parameter 1 from 'CString' to 'const char *' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called.
It's complaining about converting from a 'const char[4]'into an ATL::CStringT<wchar_t,StrTraitMFC_DLL...etc
I'm using MFC with a Unicode build, I cant change it to multi-byte, I tried and it broke the program.
I'm really lost here, little help please.