Thread: Extracting a sub-String

  1. #1
    Registered User
    Join Date
    Feb 2003

    Question Extracting a sub-String

    I am new to C and I have a requirement that is causing a few problems. I have to extract a substring from a string.

    The substring is a date in the form of YYYYMMDDHHMMSS and I know that the string I need to extract this from is in the form of...


    Where the GR_ bit is always constant in any string that my code will process.

    Since I know the start position and length (4 and 14 respectively) of the bit I require I thought it would be easy. I was kind of expecting a string function which allowed me to nominate these values and return to me the value I require.

    Reading through various sources there doesn't seem to any such function. Can someone give me some advice

    Thanks in Advance


  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    How about strncpy ?

    const char s1[] = "GR_YYYYMMDDHHMMSS_nnnn";
    char s2[15];
    strncpy(s2, s1+3, 14);
    s2[14] = '\0';

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM