some string function

This is a discussion on some string function within the Windows Programming forums, part of the Platform Specific Boards category; if i have a CString that is "30/2/2002" how can i make that i make the 30 to one variable ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    77

    some string function

    if i have a CString that is "30/2/2002"
    how can i make that i make the 30 to one variable and 2 to another...
    is there any function that will allow mi to do it ???

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Run through a for loop from 1 to strlen(yourstring). Set 2 int variables to hold position of last "/" and current "/". On each iteration of the loop test to see if you've encountered a "/" if you have use the 2 position-holding int's to get the section of data you need. Set your variable to that data (after you convert it from
    int to char/string).

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    77
    Originally posted by jdinger
    Run through a for loop from 1 to strlen(yourstring). Set 2 int variables to hold position of last "/" and current "/". On each iteration of the loop test to see if you've encountered a "/" if you have use the 2 position-holding int's to get the section of data you need. Set your variable to that data (after you convert it from
    int to char/string).
    how you use it
    can u have any example??

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Code:
    char     *pStart=NULL,sString[64];
    
    pStart=sString;//set to the start of the buffer
    while(*pStart!='\0')
    {
       iNumber1=atoi(pStart);
       while(*pStart++ != '/');
       iNumber2=atol(pStart);
       while(*pStart++ != '/');
       iNumber3=atoi(pStart);
    }
    PS try storing the dates as a long

    30 April 2002 = 30042002 (depending where you live)
    and writting some functions to convert between them.
    Some macros like
    #define GETDAY(lDate) (lDate / 1000000)
    #define GETMONTH(lDate) ((lDate / 10000) % 100)
    #define GETYEAR(lDate) (lDate % 10000)

    will help
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  4. Replies: 4
    Last Post: 03-03-2006, 01:11 AM
  5. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21