#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    0
    Rep Power
    0

    Question copying a string


    I would like to know how I would go about copying one string from another, with the added option of stating from where I want to copy.

    I know that you can use the strncpy() function to specify how many chars you want to copy.

    But I don't want to copy from the start of the string neccesarily. I might want to copy from char no 5.

    Hope somebody can help

    Thanks

    dries
  2. #2
  3. *bounce*
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Delft, The Netherlands
    Posts
    514
    Rep Power
    42
    In that case you'll still be using strncpy; instead of passing a pointer to the start of the source string, you'll pass a pointer to the fifth char in the string:

    Code:
    char *src, *dst;
    .
    .
    .
    strncpy (dst, src + 5, strlen(s) + 1 - 5;
    Watch out for overstepping boundaries though; that's nasty...
    "A poor programmer is he who blames his tools."
    http://analyser.oli.tudelft.nl/
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    new york
    Posts
    84
    Rep Power
    13
    for String objects you can use this:

    theString.copy(str, x, n);

    // Compares theString and str, starting
    // at position x, and continuing for n
    // characters.


    justin_dago

IMN logo majestic logo threadwatch logo seochat tools logo