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

    Join Date
    Sep 2003
    Posts
    13
    Rep Power
    0

    Question How to get last 3 characters from a string?


    :D Hi all, I'm new to C++ and this forum.

    ok,here is the problem. the function is supposed to creat a customer ID made up of:-

    First little of name,second name, and surname
    Hyphon character
    First 3 characters of streat
    Last 3 characters of city

    There is no error with complie, but the program doesn't display the customer ID.

    here's my code:


    string fCustomerID(string firstName,string secName,string surName,string printPerson,string city)
    {
    string printCustomerID;
    int size;

    size = city.length();

    printCustomerID = "Customer ID: " + firstName.substr(0,1) + secName.substr(0,1)
    + surName.substr(0,1) + "-" + printPerson.substr(0,3) + city.substr(size-2,3);

    return printCustomerID;
    }
    THANKS
    Last edited by goodwilllV; September 12th, 2003 at 10:08 AM.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Try size - 3 instead of size - 2:
    Code:
    printCustomerID = "Customer ID: " + firstName.substr(0,1) + secName.substr(0,1) 
    + surName.substr(0,1) + "-" + printPerson.substr(0,3) + city.substr(size-3,3);
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    13
    Rep Power
    0

    Unhappy THANKS


    thank u for ur reply!

    however, the problem just like it was by size-3.

IMN logo majestic logo threadwatch logo seochat tools logo