CString s="A"; long i=2; HOW to add i to s to get  "A2" in other CString ?

Posted on 2005-05-15
Last Modified: 2013-11-20
All is in title :)
Please simple solution ever NOT so fast.

I seek 30 minutes and CAN not find how to do it :)
In VB 6 I just will write
NewString = s & i
Question by:dvplayltd

    Author Comment

    Come on, it i easy ! The fastest expert will win !
    LVL 30

    Expert Comment

    Example code:

    NewString.Format("%s%i", s, i);
    LVL 30

    Accepted Solution

    Using the CString::Format method, you can easily put different types together.
    In the code below, %s represents a string, and %i represents a number.

    CString s = "A";
    long i = 2;
    CString NewString;
    NewString.Format("%s%i", s, i);

    You can also use itoa to convert a number to a string, but the above CString::Format method is better in general

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
    Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now