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. Managed C++/CLI
  4. How to Use String::Format Method

How to Use String::Format Method

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++tutorial
8 Posts 4 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.
  • N Offline
    N Offline
    Nagaraju_Focus
    wrote on last edited by
    #1

    Hi All, I am New user for vc.net, My code is String ^str1=L"1",^str2=L"2",^str3=L"3"; String ^str=String::Format("{0}{1}{2}",str1,str2,str3); MessageBox::Show(str); But I want Increase the String length like in VC++; CString str; str.Format("%25s%15s%15s",str1,str2,str3); I want modify above code like that Plz suggest me Nagaraju

    L G 2 Replies Last reply
    0
    • N Nagaraju_Focus

      Hi All, I am New user for vc.net, My code is String ^str1=L"1",^str2=L"2",^str3=L"3"; String ^str=String::Format("{0}{1}{2}",str1,str2,str3); MessageBox::Show(str); But I want Increase the String length like in VC++; CString str; str.Format("%25s%15s%15s",str1,str2,str3); I want modify above code like that Plz suggest me Nagaraju

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      You need to look into formatting support in .NET. String.Format does not do formatting just template placement. ToString() supports formatting. Also see IFormatProvider and NumberFormatInfo etc. String ^str=String::Format("{0}{1}{2}",**str1->ToString(IFormatProvider)**,str2,str3);

      led mike

      B 1 Reply Last reply
      0
      • L led mike

        You need to look into formatting support in .NET. String.Format does not do formatting just template placement. ToString() supports formatting. Also see IFormatProvider and NumberFormatInfo etc. String ^str=String::Format("{0}{1}{2}",**str1->ToString(IFormatProvider)**,str2,str3);

        led mike

        B Offline
        B Offline
        bob16972
        wrote on last edited by
        #3

        What! no printf style formatting support? What kind of C based language does not somehow provide printf style formatting. Last I heard, even Java 1.5 or 5.0 or whatever it is added printf style formatting to their string class. -- modified at 12:46 Tuesday 8th August, 2006

        L 1 Reply Last reply
        0
        • B bob16972

          What! no printf style formatting support? What kind of C based language does not somehow provide printf style formatting. Last I heard, even Java 1.5 or 5.0 or whatever it is added printf style formatting to their string class. -- modified at 12:46 Tuesday 8th August, 2006

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          bob16972 wrote:

          What kind of C based language

          If you are doing mixed mode you can still use the C++ formatting libraries.

          bob16972 wrote:

          Last I heard, even Java 1.5 or 5.0 or whatever it is added printf style formatting to their string class.

          Have not done any Java in the past couple of years, don't know if I ever will again.

          led mike

          B 1 Reply Last reply
          0
          • L led mike

            bob16972 wrote:

            What kind of C based language

            If you are doing mixed mode you can still use the C++ formatting libraries.

            bob16972 wrote:

            Last I heard, even Java 1.5 or 5.0 or whatever it is added printf style formatting to their string class.

            Have not done any Java in the past couple of years, don't know if I ever will again.

            led mike

            B Offline
            B Offline
            bob16972
            wrote on last edited by
            #5

            just a disclaimer... That wasn't meant toward you. I was gasping aloud so my apologies if that came off as somehow blaming you. When I reread it, it just doesn't sound right so again, my apologies. :)

            L 1 Reply Last reply
            0
            • N Nagaraju_Focus

              Hi All, I am New user for vc.net, My code is String ^str1=L"1",^str2=L"2",^str3=L"3"; String ^str=String::Format("{0}{1}{2}",str1,str2,str3); MessageBox::Show(str); But I want Increase the String length like in VC++; CString str; str.Format("%25s%15s%15s",str1,str2,str3); I want modify above code like that Plz suggest me Nagaraju

              G Offline
              G Offline
              George L Jackson
              wrote on last edited by
              #6

              You can do this: String ^str = String::Format("{0,25}{1,15}{2,15}", str1, str2, str3); for with the values right-aligned and this: String ^str = String::Format("{0,-25}{1,-15}{2,-15}", str1, str2, str3); for values left-aligned. -- modified at 15:35 Tuesday 8th August, 2006

              N 1 Reply Last reply
              0
              • B bob16972

                just a disclaimer... That wasn't meant toward you. I was gasping aloud so my apologies if that came off as somehow blaming you. When I reread it, it just doesn't sound right so again, my apologies. :)

                L Offline
                L Offline
                led mike
                wrote on last edited by
                #7

                :laugh: I knew that but thanks for the concern, Also see George Jacksons reply which shows how String.Format uses format specifiers. He picked up my slack. :)

                led mike

                1 Reply Last reply
                0
                • G George L Jackson

                  You can do this: String ^str = String::Format("{0,25}{1,15}{2,15}", str1, str2, str3); for with the values right-aligned and this: String ^str = String::Format("{0,-25}{1,-15}{2,-15}", str1, str2, str3); for values left-aligned. -- modified at 15:35 Tuesday 8th August, 2006

                  N Offline
                  N Offline
                  Nagaraju_Focus
                  wrote on last edited by
                  #8

                  Thank U very Much George, I wish u all the best Nagaraju

                  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