#42 Right(4).Left(2) vs sbustr function

closed
Psychon
Modules (21)
5
2008-09-08
2008-07-23
Anonymous
No

VCString vLogs;

... code for reading dir list ...

for(int ii=0; ii < vLogs.size(); ii++)
{
CString tName = vLogs[ii].Left(vLogs[ii].size()-8);
CString tDate = vLogs[ii].Right(8);
CString tYear = tDate.Left(4);
// CString tMonth = tDate.Right(4).Left(2);
CString tMonth = tDate.substr(4,2);
CString tDay = tDate.Right(2);
PutModule(vLogs[ii] + " " + tName + " " + tDate);
PutModule(tYear + "." + tMonth + "." + tDay + " | " + tName);
}

This code I use in module log (log.cpp) on OnModCommand event.

In vLogs I save list of files with date info. Example:
vLogs[0] = "#channel_20080723"

If I use Right and Left methods as Right(4).Left(2), then I have not correct value.
But if I use substr function, then tMonth is correct.

Why?

Discussion

  • Nobody/Anonymous

    Logged In: NO

    Uhm, I can't reproduce.

    This code in main()

    CString s = "20080723";
    cout << "Year : " << s.Left(4);
    cout << "\nMonth: " << s.Right(4).Left(2);
    cout << "\nDay : " << s.Right(2);
    cout << endl;
    return 0;

    gives this output:
    Year : 2008
    Month: 07
    Day : 23

    which seems totally fine to me. Something else must be wrong.

     
  • Psychon

    Psychon - 2008-08-24
    • assigned_to: prozacx --> psychon
    • status: open --> pending
     
  • Psychon

    Psychon - 2008-08-24

    Logged In: YES
    user_id=1654410
    Originator: NO

    Marking this as pending, submitter didn't reply anymore.

     
  • SourceForge Robot

    Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending --> closed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks