Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to add a character in the begin and end of the string?

How to add a character in the begin and end of the string?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ashokbngr
    wrote on last edited by
    #1

    in the begin and end of "abc xyz" I want to display "[abc xyz]" help me ...:confused: Thanks in advance Ashok

    T N K B 4 Replies Last reply
    0
    • A ashokbngr

      in the begin and end of "abc xyz" I want to display "[abc xyz]" help me ...:confused: Thanks in advance Ashok

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      CString str = _T("abc xyz");

      str = _T("[") + str + _T("]");


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      1 Reply Last reply
      0
      • A ashokbngr

        in the begin and end of "abc xyz" I want to display "[abc xyz]" help me ...:confused: Thanks in advance Ashok

        N Offline
        N Offline
        Nibu babu thomas
        wrote on last edited by
        #3

        ashokbngr wrote:

        in the begin and end of "abc xyz" I want to display "[abc xyz]"

        CString csStr;
        csStr.Format( _T( "[%s]" ), _T( "abc xyz" ));


        Nibu thomas A Developer Programming tips[^]  My site[^]

        1 Reply Last reply
        0
        • A ashokbngr

          in the begin and end of "abc xyz" I want to display "[abc xyz]" help me ...:confused: Thanks in advance Ashok

          K Offline
          K Offline
          krmed
          wrote on last edited by
          #4

          You can use the CString.Insert method and the += operator:

          CString myString = "abc xyz";
          myString.Insert(0, '[');
          myString += "]";

          See MSDN CString.Insert[^] Hope that helps.

          Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

          1 Reply Last reply
          0
          • A ashokbngr

            in the begin and end of "abc xyz" I want to display "[abc xyz]" help me ...:confused: Thanks in advance Ashok

            B Offline
            B Offline
            balu chettri
            wrote on last edited by
            #5

            CString s1 = "abc xyz"; CString s2 = "[" + s1 + "]";

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups