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#
  4. string.format

string.format

Scheduled Pinned Locked Moved C#
help
13 Posts 7 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.
  • T Offline
    T Offline
    tek 2009
    wrote on last edited by
    #1

    I read many articles on String.Format, in my case I have a string variable that I want to specify its format 10a (a is alpha-numeric), I would like you to help me write this instruction , thank you in advance

    J realJSOPR P L 5 Replies Last reply
    0
    • T tek 2009

      I read many articles on String.Format, in my case I have a string variable that I want to specify its format 10a (a is alpha-numeric), I would like you to help me write this instruction , thank you in advance

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      This may seem a little wacky, but String.Format is generally used for formatting other types to a string. Strings themselves cannot really be formatted in any meaningful way. Perhaps you could explain your problem a little more, and then maybe someone can help you with a solution.

      T 1 Reply Last reply
      0
      • J J4amieC

        This may seem a little wacky, but String.Format is generally used for formatting other types to a string. Strings themselves cannot really be formatted in any meaningful way. Perhaps you could explain your problem a little more, and then maybe someone can help you with a solution.

        T Offline
        T Offline
        tek 2009
        wrote on last edited by
        #3

        So in my case I have a table which contains 6 colomns which corresponds to a code and its value, and this table contains the characteristics of this value with format.donc to read a file from the code and its value must be correctly formatted according to the table, so I need to specify the format in 10 alpha numeric, so how do this??

        T 1 Reply Last reply
        0
        • T tek 2009

          I read many articles on String.Format, in my case I have a string variable that I want to specify its format 10a (a is alpha-numeric), I would like you to help me write this instruction , thank you in advance

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #4

          I believe this should do it.

          myString = myString.PadLeft(10);

          .45 ACP - because shooting twice is just silly
          -----
          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

          1 Reply Last reply
          0
          • T tek 2009

            I read many articles on String.Format, in my case I have a string variable that I want to specify its format 10a (a is alpha-numeric), I would like you to help me write this instruction , thank you in advance

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #5

            If you want "10a" (as opposed to " a"), you would use

            myString = string.Format("10{0}", a);

            .45 ACP - because shooting twice is just silly
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

            1 Reply Last reply
            0
            • T tek 2009

              So in my case I have a table which contains 6 colomns which corresponds to a code and its value, and this table contains the characteristics of this value with format.donc to read a file from the code and its value must be correctly formatted according to the table, so I need to specify the format in 10 alpha numeric, so how do this??

              T Offline
              T Offline
              The Man from U N C L E
              wrote on last edited by
              #6

              I would recommend a validation process. If you try to format the return you will get spurious results. Try using Regular Expressions to validate the value. ^[a-zA-Z0-9]{10}\z should do the job.

              If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

              1 Reply Last reply
              0
              • T tek 2009

                I read many articles on String.Format, in my case I have a string variable that I want to specify its format 10a (a is alpha-numeric), I would like you to help me write this instruction , thank you in advance

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                It's unclear what you are asking; please provide "before" and "after" examples.

                1 Reply Last reply
                0
                • T tek 2009

                  I read many articles on String.Format, in my case I have a string variable that I want to specify its format 10a (a is alpha-numeric), I would like you to help me write this instruction , thank you in advance

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  myString = myString.PadLeft(10, '0');

                  would keep it all-alphanumeric. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read formatted code with indentation, so please use PRE tags for code snippets.


                  I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                  T 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    myString = myString.PadLeft(10, '0');

                    would keep it all-alphanumeric. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                    I only read formatted code with indentation, so please use PRE tags for code snippets.


                    I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                    T Offline
                    T Offline
                    Thomas Krojer
                    wrote on last edited by
                    #9

                    string.Format("{0,10}", "a")

                    L T 2 Replies Last reply
                    0
                    • T Thomas Krojer

                      string.Format("{0,10}", "a")

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      that fills with spaces, one could argue the result isn't all alphanumeric. :)

                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                      I only read formatted code with indentation, so please use PRE tags for code snippets.


                      I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                      T 1 Reply Last reply
                      0
                      • L Luc Pattyn

                        that fills with spaces, one could argue the result isn't all alphanumeric. :)

                        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                        I only read formatted code with indentation, so please use PRE tags for code snippets.


                        I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                        T Offline
                        T Offline
                        tek 2009
                        wrote on last edited by
                        #11

                        thank you very much to all of you, I'll try all these proposals and I will post the solution works

                        1 Reply Last reply
                        0
                        • T Thomas Krojer

                          string.Format("{0,10}", "a")

                          T Offline
                          T Offline
                          tek 2009
                          wrote on last edited by
                          #12

                          So we must convert the type specified by theFormatting Numeric Results Table [] that correct??

                          modified on Friday, May 21, 2010 1:04 PM

                          realJSOPR 1 Reply Last reply
                          0
                          • T tek 2009

                            So we must convert the type specified by theFormatting Numeric Results Table [] that correct??

                            modified on Friday, May 21, 2010 1:04 PM

                            realJSOPR Offline
                            realJSOPR Offline
                            realJSOP
                            wrote on last edited by
                            #13

                            Dude - only you know the requirements.

                            .45 ACP - because shooting twice is just silly
                            -----
                            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                            -----
                            "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                            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