|
Shaunak De wrote: If you are searching for a string in a text file...
Which I'm not, but thanks anyway, though.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
tahnks for your help ...i need this code in visual c++ and i use visual c++ 2008/2010. could you help me with this? I place the word that i want to search in a textbox and after i click on a button(search) i want to see where the word is. The file is loaded in a richtextbox . thanks a lot
|
|
|
|
|
|
your help was appreciated but what i wana do is to write the word in a text box and after i click on a button(search) it will show me where the word is (in my richtextbox where the text file is loaded) all these in my windows form. any idea? thanks a lot
|
|
|
|
|
Hello,
I need a function that would do a parse exact on a CString - given a format - and return a date (or an exception!)
Eg
COleDateTime timParsed;
timParsed.ParseExact("2002 10 3","yyyy mm d");
I am aware of ParseDateTime... but I need something where you actually specify the expected format! And I knoe ParseExact is in .net but hey I am stuck in the nineties!
Any idea?
Thanks!
Jerry
|
|
|
|
|
You may use time_from_string() from boost::posix_time , port the OpenSource code of the BSD strptime() function, or write a parser yourself (e.g. using sscanf() ).
|
|
|
|
|
I have had some success in the past using strftime() [^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
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) )
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.
|
|
|
|
|
Richard pointed out using strftime( ) . it is standard C.
#include <cstdio>
#include <ctime>
int main ()
{
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"%Y %m %d ",timeinfo);
puts (buffer);
return 0;
}
|
|
|
|
|
Yes but I want to parse not to format!
Thanks!
Jerry
|
|
|
|
|
My apologies, I got mixed up, and cannot for the life of me recall the function that does the parsing.
[edit]
It's strptime() which, unfortunately, is not available in Windows, so you will need to get a copy of an open source version from somewhere.
[/edit]
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Richard MacCutchan wrote: It's strptime() which, unfortunately, is not available in Windows
Very odd. Far as I can tell strptime is not part of ANSI C. Which makes me wonder why.
|
|
|
|
|
It's POSIX according to the man page[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
My mistake. Didn't notice that CStrings only compile in MFC.
char buffer[256];
CString cs = buffer;
CString Management[^]
|
|
|
|
|
You can still use the ParseDateTime, but you need to set the format first.
Here's what I've done...
First, get the current format using
GetLocaleInfo(m_LCID, LOCALE_SSHORTDATE, m_csOriginalSDateFormat.GetBuffer(MAX_PATH + 1), MAX_PATH);
m_csOriginalSDateFormat.ReleaseBuffer();
(m_csOriginalSDateFormat is a CString)
Next have your own CString with the desired format:
m_csNewSDateFormat = _T("M/d/yyyy");
Now, set the desired format, parse the date/time, and restore the original format:
SetLocaleInfo(m_LCID, LOCALE_SSHORTDATE, m_csNewSDateFormat);
oleStartTime.ParseDateTime(csDateTime);
SetLocaleInfo(m_LCID, LOCALE_SSHORTDATE, m_csOriginalSDateFormat);
Hope this helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
|
|
Thanks again... but this is to return a string with a format...
What I wanted is to parse a string into a date with a format!
Something like
COleDatetime t;
t.IsThisStringADateWithThisFormat(_T("10012012"),"ddMMyyyy");
But I have managed (see my post above)!
Thanks anyway!
Jerry
|
|
|
|
|
hi,
i have developed program where two separate windows, one containing Map and other the dialog form with some controls, are opened. the program is when i click on Map window, its coordinates are displayed in the static text on the dialog form window. what i want is that when i click on Map window (which is at the front at the time of clicking) the dialog form window should appear at the front showing the results of my click, i.e the coordinates.
Regards
Jawad
modified 18-Jul-12 4:00am.
|
|
|
|
|
When you click on the map you can set the dialog's property to WS_EX_TOPMOST as described here[^]. You would then need to reset that value on some other action. Alternatively you could use the SetWindowPos() [^] function to alter its place in the Z-order, i.e. bring it to the front.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
thank you Richard MacCutchan.
|
|
|
|
|
in my app, I use ftp raw commands to upload several files to server,
after sending PASV and STOR from command port, file transfer starts on data port - so far so good.
But, when I send same commands to server again to upload second file before first uploading completed , server answers "unknowing command" - to second PASV and STOR.
So, I have to wait for first uploading completed to upload second file.
Any comments as solution?
Anything wrong in my ftp commands or process?
how to upload 2 or more files at same time?
how to open multiple data sockets (ports) with one command socket (port)?
Thanks.
.
|
|
|
|
|
Just a guess, but wouldn't you need to create a second connection to the server to upload the second file simultaneously?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
The number of simultaneous transfers is under control of the server. When you send PASV, it will respond with none, one or more lines indicating a data port on which it is listening. If you can't work it out from reading manuals (RFC959 is a good start), find a real server that works, and get Wireshark on the job to see what messages go back and forth. (A good server like Filezilla maintains a log so you probably don't need Wireshark, but it'll be useful when you come to debugging your own code.)
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
hi
am looking to move the existing file along with progress control update .
i tried with movefilewithprogrees did not work .
canany body explain the concept
movefilewithprogrees how it work or any alternate way for moving the file with progress update .
this movefilewithprogress will move the file if i get how much this function will transfer the data .
Best
Regards
sarfaraz
|
|
|
|
|