Click here to Skip to main content
15,927,347 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
General#include <afxdtctl.h> Pin
10-Sep-01 13:28
suss10-Sep-01 13:28 
GeneralRe:The file was afxdtctl.h Pin
10-Sep-01 13:56
suss10-Sep-01 13:56 
GeneralRe:The file was afxdtctl.h Pin
Michael Dunn10-Sep-01 15:29
sitebuilderMichael Dunn10-Sep-01 15:29 
QuestionOwner Drawn means? Pin
10-Sep-01 12:57
suss10-Sep-01 12:57 
AnswerRe: Owner Drawn means? Pin
Christian Graus10-Sep-01 14:01
protectorChristian Graus10-Sep-01 14:01 
GeneralCentering dialog boxes Pin
10-Sep-01 12:55
suss10-Sep-01 12:55 
GeneralRe: Centering dialog boxes Pin
Not Active10-Sep-01 14:19
mentorNot Active10-Sep-01 14:19 
GeneralParsing Text.. Beginner Question. Pin
RobJones10-Sep-01 10:13
RobJones10-Sep-01 10:13 
Hello,
Sorry for this lengthy posting, I am trying to figure out the best way to parse text. I created a program that pulls the source HTML from a provided URL and dumps it into a text file. I am parsing through the text file then putting the parsed text into CStrings. I was wondering if there is an easier/better/cleaner way to parse text for values? Here is a sample of the code I’m using to parse. Any ideas to make this easier or more efficient would be greatly appreciated.

//This parses the html for the month
		int nMyIndexMoPDT, nFirstIndexMoPDT, nSecondIndexMoPDT;
		nMyIndexMoPDT = strPDT.Find(_T("the time will be..."));
		nFirstIndexMoPDT = strPDT.Find(_T(","), nMyIndexMoPDT);
		nSecondIndexMoPDT = strPDT.Find(_T(","), nFirstIndexMoPDT+1);
		strPDTMo = strPDT.Mid(nFirstIndexMoPDT+1, nSecondIndexMoPDT-nFirstIndexMoPDT-1);
		strPDTMo.TrimLeft(_T(" "));
		strMonthsPDT = strPDTMo.Left(3);
			
		//This parses the html for the Current Time PDT
		//Vaule should look like 00:00:00 after this part
		int nMyIndexPDT, nFirstIndexPDT, nSecondIndexPDT;
		nMyIndexPDT = strPDT.Find(_T("tone"));
		nFirstIndexPDT = strPDT.Find(_T(">"), nMyIndexPDT);
		nSecondIndexPDT = strPDT.Find(_T("<"), nFirstIndexPDT+1);
		strPDT1 = strPDT.Mid(nFirstIndexPDT, nSecondIndexPDT-3-nFirstIndexPDT-1);
		strPDT = strPDT1.Right(8);
		
		//This parses the html for the current day 2 parts
		int nMyIndexPDTDays, nFirstIndexPDTDays, nSecondIndexPDTDays;
		nMyIndexPDTDays = strPDT.Find(_T("At the tone, the time will be..."));
		nFirstIndexPDTDays = strPDT.Find(_T("b"), nMyIndexPDTDays);
		nSecondIndexPDTDays = strPDT.Find(_T("<"), nFirstIndexPDTDays);
		strPDTDays = strPDT.Mid(nFirstIndexPDTDays+3, nSecondIndexPDTDays-nFirstIndexPDTDays-3);
		
		//At this point the string should be "Wednesday, Jul 10, 2001 00:00:00 PDT"	
		//The next bit of code pulls the day out the string should be "10" for example
		int nMyIndexPDTDaysTemp = strPDTDays.Find(_T(","));
		int nFirstIndexPDTDaysTemp = strPDTDays.Find(_T(","));
		int nSecondIndexPDTDaysTemp = strPDTDays.Find(_T(","), nMyIndexPDTDaysTemp+1);
		CString strDaysP1 = strPDTDays.Mid(nFirstIndexPDTDaysTemp+1,
nSecondIndexPDTDaysTemp-nFirstIndexPDTDaysTemp-1);
		CString strDaysP2 = strDaysP1.Right(2);
		iPDTD = atoi(strDaysP2);
	
		//Are the hours 1 or 2 digits? Hours Extraction
		//This part looks at the 00:00:00 and extracts the Left 2 digits
		strPDTHours = strPDT.Left(2);
		if(strPDTHours.Right(1) == _T(":"))
		{
			strPDTHours = strPDT.Left(1);
		}
		int iPDTHours = atoi(strPDTHours); 
		iPDTH = iPDTHours;
	
		//Minutes Extraction
		//This part looks at the 00:00:00 and extracts the middle "00"
		int nMyIndexPDTMins, nFirstIndexPDTMins, nSecondIndexPDTMins;
		nMyIndexPDTMins = strPDT.Find(_T(":"));
		nFirstIndexPDTMins = strPDT.Find(_T(":"), nMyIndexPDTMins);
		nSecondIndexPDTMins = strPDT.Find(_T(":"), nFirstIndexPDTMins+1);
		strPDTMins = strPDT.Mid(nFirstIndexPDTMins+1, nSecondIndexPDTMins-nFirstIndexPDTMins-1);
		int iPDTMins = atoi(strPDTMins);
		iPDTM = iPDTMins;
	
		//Are the Seconds 1 or 2 digits?
		//This part looks at the 00:00:00 and extracts the Right 2 digits
		strPDTSec = strPDT.Right(2);
		if(strPDTSec.Left(1) == _T(":"))
		{
			strPDTSec = strPDT.Right(1);
		}
		int iPDTSec = atoi(strPDTSec); 
		iPDTS = iPDTSec;
		//MessageBox(strPDTHours+":"+strPDTMins+":"+strPDTSec); //Used for testing


By the way, this code works. It just seems inefficient to me.Big Grin | :-D

Thanks for any ideas you may have!!!
GeneralRe: Parsing Text.. Beginner Question. Pin
Erik Thompson10-Sep-01 10:17
sitebuilderErik Thompson10-Sep-01 10:17 
GeneralRe: Parsing Text.. Beginner Question. Pin
Nemanja Trifunovic10-Sep-01 10:23
Nemanja Trifunovic10-Sep-01 10:23 
GeneralRe: Parsing Text.. Beginner Question. Pin
RobJones10-Sep-01 11:06
RobJones10-Sep-01 11:06 
GeneralRe: Parsing Text.. Beginner Question. Pin
A.R.10-Sep-01 12:46
A.R.10-Sep-01 12:46 
Generalneed help in converting Pin
10-Sep-01 10:09
suss10-Sep-01 10:09 
GeneralRe: need help in converting Pin
Erik Thompson10-Sep-01 10:19
sitebuilderErik Thompson10-Sep-01 10:19 
GeneralThank you! Pin
10-Sep-01 10:21
suss10-Sep-01 10:21 
GeneralHelp please Pin
10-Sep-01 9:36
suss10-Sep-01 9:36 
GeneralRe: Help please Pin
Christian Graus10-Sep-01 12:46
protectorChristian Graus10-Sep-01 12:46 
GeneralRe: Help please Pin
A.R.10-Sep-01 14:03
A.R.10-Sep-01 14:03 
GeneralRe: Help please Pin
Christian Graus10-Sep-01 14:16
protectorChristian Graus10-Sep-01 14:16 
GeneralRe: Help please Pin
Carlos Antollini10-Sep-01 14:40
Carlos Antollini10-Sep-01 14:40 
GeneralRe: Help please Pin
11-Sep-01 3:03
suss11-Sep-01 3:03 
GeneralMS VisionSDK or similar Video Capture tech... Pin
Joshua Guy10-Sep-01 8:19
Joshua Guy10-Sep-01 8:19 
GeneralCListCtrl Pin
10-Sep-01 5:13
suss10-Sep-01 5:13 
GeneralRe: CListCtrl Pin
Joaquín M López Muñoz10-Sep-01 6:14
Joaquín M López Muñoz10-Sep-01 6:14 
Generaldelete makes assertion fail Pin
Hano10-Sep-01 5:06
Hano10-Sep-01 5:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.