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

    Join Date
    Aug 2003
    Posts
    6
    Rep Power
    0

    strcat, any other way to join strings?


    is there another way to join strings than strcat, sort of like phps
    "." or "+" in javascript?

    basically i have a string parameter for a function, but i want to send it like

    function("Asdsadsa" + MYVARIABLE + "ASDSADS");

    but that of course doesnt work, at least not for me. Im pretty knew so please lend me your wisdom :D
  2. #2
  3. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    You can use sprintf or wsprintf, but I think strcat is more simple, this is in C. I think C++ has another way.

    sprintf(buffer, "Asdsadsa%sASDSADS", yourStringVar);
    %d for int
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,625
    Rep Power
    4247
    If you're using C++, the string class has the + operator overloaded to concatenate strings. You can also use the c_str() method to return a char * to your function. So you could cast the first item to class string, use the + operator and finally call the c_str() method to convert it back to char *. The code could go something like this:

    function((string("Asdsadsa") + MYVARIABLE + "ASDSADS").c_str());
    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
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    6
    Rep Power
    0
    great, thats exactly what i was looking for. Thanks Scorpion

IMN logo majestic logo threadwatch logo seochat tools logo