Click here to Skip to main content
15,889,739 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: search for a word in a text file Pin
David Crow20-Jul-12 4:51
David Crow20-Jul-12 4:51 
GeneralRe: search for a word in a text file Pin
byank20-Jul-12 7:28
byank20-Jul-12 7:28 
GeneralRe: search for a word in a text file Pin
Software_Developer18-Jul-12 3:40
Software_Developer18-Jul-12 3:40 
GeneralRe: search for a word in a text file Pin
byank19-Jul-12 11:05
byank19-Jul-12 11:05 
QuestionParseExact - parsing a date with a given format in C++ / MFC Pin
BadJerry18-Jul-12 0:50
BadJerry18-Jul-12 0:50 
AnswerRe: ParseExact - parsing a date with a given format in C++ / MFC Pin
Jochen Arndt18-Jul-12 2:27
professionalJochen Arndt18-Jul-12 2:27 
AnswerRe: ParseExact - parsing a date with a given format in C++ / MFC Pin
Richard MacCutchan18-Jul-12 3:20
mveRichard MacCutchan18-Jul-12 3:20 
GeneralRe: ParseExact - parsing a date with a given format in C++ / MFC Pin
BadJerry18-Jul-12 3:32
BadJerry18-Jul-12 3:32 
Thanks Jochen And Richard,

Yes I used an OpenSource version of strptime() that I found here: http://plibc.sourceforge.net/doxygen/strptime_8c-source.html[^]- and I have transformef the char(s) into TCHAR, added _T, etc....

and I ave written this:
{
	...
	CString strFormatCpp = TranslateFormatDate(strFormatVB);

	tm timeDate;
	memset(&timeDate,0,sizeof(tm ));
	TCHAR * pRes = strptime (strMyDate, strFormatCpp, &timeDate);
				
	if ( pRes != NULL )
	{
		COleDateTime oleDate;
		oleDate.SetDateTime(1900 + timeDate.tm_year,timeDate.tm_mon+1,timeDate.tm_mday,timeDate.tm_hour,timeDate.tm_min,timeDate.tm_sec);

	}
}

CString TranslateFormatDate(const CString & strFormat) 
{
	CString strResult;
	int nChar = 0;
	while ( nChar < strFormat.GetLength() )
	{
		switch ( strFormat[nChar] )
		{
		case 'A':
			if ( MatchFormatKey(_T("AMPM"),_T("%p"),strFormat, nChar,strResult) )
				continue;
			break;
		case 'a':
			if ( MatchFormatKey(_T("ampm"),_T("%p"),strFormat, nChar,strResult) ) // Lower does not exist in C++?
				continue;
		case 'y':
			if ( MatchFormatKey(_T("yyyy"),_T("%Y"),strFormat, nChar,strResult) )
				continue;
			if ( MatchFormatKey(_T("yy"),_T("%y"),strFormat, nChar,strResult) )
				continue;
			break;
		case 'M':
			if ( MatchFormatKey(_T("MMMM"),_T("%B"),strFormat, nChar,strResult) )
				continue;
			if ( MatchFormatKey(_T("MMM"),_T("%b"),strFormat, nChar,strResult) )
				continue;
			if ( MatchFormatKey(_T("MM"),_T("%m"),strFormat, nChar,strResult) )
				continue;
			if ( MatchFormatKey(_T("M"),_T("%#m"),strFormat, nChar,strResult) ) 
				continue;
			break;
		case 'd':
			if ( MatchFormatKey(_T("dddd"),_T("%A"),strFormat, nChar,strResult) )
				continue;
			if ( MatchFormatKey(_T("ddd"),_T("%a"),strFormat, nChar,strResult) )
				continue;
			if ( MatchFormatKey(_T("dd"),_T("%d"),strFormat, nChar,strResult) )
				continue;
			if ( MatchFormatKey(_T("d"),_T("%#d"),strFormat, nChar,strResult) )
				continue;
			break;
		case 'h':
			if ( MatchFormatKey(_T("hh"),_T("%I"),strFormat, nChar,strResult) )
				continue;
			if ( MatchFormatKey(_T("h"),_T("%#I"),strFormat, nChar,strResult) )
				continue;
			break;
		case 'H':
			if ( MatchFormatKey(_T("HH"),_T("%H"),strFormat, nChar,strResult) )
				continue;
			if ( MatchFormatKey(_T("H"),_T("%#H"),strFormat, nChar,strResult) )
				continue;
			break;
		case 'm':
			if ( MatchFormatKey(_T("mm"),_T("%M"),strFormat, nChar,strResult) )
				continue;
			if ( MatchFormatKey(_T("m"),_T("%#M"),strFormat, nChar,strResult) )
				continue;
			break;
		case 's':
			if ( MatchFormatKey(_T("ss"),_T("%S"),strFormat, nChar,strResult) )
				continue;
			if ( MatchFormatKey(_T("s"),_T("%#S"),strFormat, nChar,strResult) )
				continue;
			break;
		}

		strResult+=strFormat[nChar];
		nChar++;
	}

	return strResult;
}

bool MatchFormatKey(const CString & strKey,const CString & strTransKey,const CString & strFormat, int & nPos,CString & strResult) 
{
	if ( strFormat.Mid(nPos, strKey.GetLength()) != strKey )
		return false;

	strResult+=strTransKey;
	nPos+=strKey.GetLength();

	return true;
}


Thanks every-one!
Jerry

modified 18-Jul-12 9:49am.

AnswerRe: ParseExact - parsing a date with a given format in C++ / MFC Pin
Software_Developer18-Jul-12 4:54
Software_Developer18-Jul-12 4:54 
GeneralRe: ParseExact - parsing a date with a given format in C++ / MFC Pin
BadJerry18-Jul-12 5:41
BadJerry18-Jul-12 5:41 
GeneralRe: ParseExact - parsing a date with a given format in C++ / MFC Pin
Richard MacCutchan18-Jul-12 7:39
mveRichard MacCutchan18-Jul-12 7:39 
GeneralRe: ParseExact - parsing a date with a given format in C++ / MFC Pin
jschell20-Jul-12 7:28
jschell20-Jul-12 7:28 
GeneralRe: ParseExact - parsing a date with a given format in C++ / MFC Pin
Richard MacCutchan20-Jul-12 9:21
mveRichard MacCutchan20-Jul-12 9:21 
GeneralRe: ParseExact - parsing a date with a given format in C++ / MFC Pin
Software_Developer18-Jul-12 21:12
Software_Developer18-Jul-12 21:12 
AnswerRe: ParseExact - parsing a date with a given format in C++ / MFC Pin
krmed18-Jul-12 10:04
krmed18-Jul-12 10:04 
GeneralRe: ParseExact - parsing a date with a given format in C++ / MFC Pin
BadJerry18-Jul-12 22:45
BadJerry18-Jul-12 22:45 
GeneralRe: COleDateTime::Format("%A, %B %d, %Y") Pin
Software_Developer19-Jul-12 6:16
Software_Developer19-Jul-12 6:16 
GeneralRe: COleDateTime::Format("%A, %B %d, %Y") Pin
BadJerry19-Jul-12 7:08
BadJerry19-Jul-12 7:08 
Generalset focus to main dialog form in MFC (SOLVED) Pin
jawadali47717-Jul-12 18:05
jawadali47717-Jul-12 18:05 
AnswerRe: set focus to main dialog form in MFC Pin
Richard MacCutchan17-Jul-12 21:48
mveRichard MacCutchan17-Jul-12 21:48 
GeneralRe: set focus to main dialog form in MFC Pin
jawadali47717-Jul-12 22:00
jawadali47717-Jul-12 22:00 
Questionftp : to upload multile files at same time Pin
includeh1017-Jul-12 4:27
includeh1017-Jul-12 4:27 
QuestionRe: ftp : to upload multile files at same time Pin
David Crow17-Jul-12 9:59
David Crow17-Jul-12 9:59 
AnswerRe: ftp : to upload multile files at same time Pin
Peter_in_278017-Jul-12 18:16
professionalPeter_in_278017-Jul-12 18:16 
QuestionMoving file with progress Pin
sarfaraznawaz17-Jul-12 1:02
sarfaraznawaz17-Jul-12 1:02 

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.