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. complicated string

complicated string

Scheduled Pinned Locked Moved C#
question
7 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.
  • B Offline
    B Offline
    bfis108137
    wrote on last edited by
    #1

    I am not sure if it's even possible to do this but I am trying to print out a list of various data but I don't want to put a datagridview in the form. So my question is this. Is there someway that I can build a string to skip to a certain point like something the tab might do so I could have what would look like columns?

    realJSOPR 1 Reply Last reply
    0
    • B bfis108137

      I am not sure if it's even possible to do this but I am trying to print out a list of various data but I don't want to put a datagridview in the form. So my question is this. Is there someway that I can build a string to skip to a certain point like something the tab might do so I could have what would look like columns?

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

      Ignoring the fact that you haven't mentioned any details regarding how the string is to be processed (do you want to select specific parts of it?), I assume that the "certain point" that you want to skip would be likely to be different from string to string, so... You could create an object that accepts a string in the constructor call, and then implement an override of the ToString() method that accepts an enum (again, one that you define) that can change the way the string is processed. Or you could simply write a method that processes the string according to the enum value passed as a parameter. It's almost impossible to provide relevant advice with so little to go on.

      "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." - Jason Jystad, 10/26/2001

      B 1 Reply Last reply
      0
      • realJSOPR realJSOP

        Ignoring the fact that you haven't mentioned any details regarding how the string is to be processed (do you want to select specific parts of it?), I assume that the "certain point" that you want to skip would be likely to be different from string to string, so... You could create an object that accepts a string in the constructor call, and then implement an override of the ToString() method that accepts an enum (again, one that you define) that can change the way the string is processed. Or you could simply write a method that processes the string according to the enum value passed as a parameter. It's almost impossible to provide relevant advice with so little to go on.

        "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." - Jason Jystad, 10/26/2001

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

        honestly I don't really know. First of all this is for my programming project for my .net course so that should tell you how new I am. I basically have a list of books, but for each book there is a name, publisher, unit cost, copies ordered, and total cost. I must print the list out, but I want all the items to be lined up so it don't just look messy. I could go about it another way if you have a suggestion, I just don't know.

        B realJSOPR N 3 Replies Last reply
        0
        • B bfis108137

          honestly I don't really know. First of all this is for my programming project for my .net course so that should tell you how new I am. I basically have a list of books, but for each book there is a name, publisher, unit cost, copies ordered, and total cost. I must print the list out, but I want all the items to be lined up so it don't just look messy. I could go about it another way if you have a suggestion, I just don't know.

          B Offline
          B Offline
          Ben Fair
          wrote on last edited by
          #4

          Create the string and use "\t" where you want the tabs.

          Hope in one hand and poop in the other; see which fills up first. Hope and change were good slogans, now show us more than words.

          S 1 Reply Last reply
          0
          • B Ben Fair

            Create the string and use "\t" where you want the tabs.

            Hope in one hand and poop in the other; see which fills up first. Hope and change were good slogans, now show us more than words.

            S Offline
            S Offline
            SeMartens
            wrote on last edited by
            #5

            Or you could use padding. For example you can define 200 characters for the title by padding all book titles during print out.

            string sCurBookColumnValue = "MyBook".PadRight(200).

            Do this for all values, this will format your string while writing it on the console.

            It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

            1 Reply Last reply
            0
            • B bfis108137

              honestly I don't really know. First of all this is for my programming project for my .net course so that should tell you how new I am. I basically have a list of books, but for each book there is a name, publisher, unit cost, copies ordered, and total cost. I must print the list out, but I want all the items to be lined up so it don't just look messy. I could go about it another way if you have a suggestion, I just don't know.

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

              Ahhh, so you need to parse the string, and then you want to make it pretty when you print by lining up columns of data... I'm assuming that it's a console application (because making it pretty in a forms app would be much easier, and less work to boot). You could brute-force it and use string.Format to pad each string, or you could read in the data, parse each string to find the longest name, publisher, etc., and then format with appropriate padding for each column. I think he first way would earn you a passing grade, and would take far less time, but the second way would teach you more (and be more fun besides). Which path will you take? My advice is to satisfy the minimum requirements by doing it the first way, but then do it the second way and if you finish it in time, hand the 2nd version in instead.

              "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." - Jason Jystad, 10/26/2001

              1 Reply Last reply
              0
              • B bfis108137

                honestly I don't really know. First of all this is for my programming project for my .net course so that should tell you how new I am. I basically have a list of books, but for each book there is a name, publisher, unit cost, copies ordered, and total cost. I must print the list out, but I want all the items to be lined up so it don't just look messy. I could go about it another way if you have a suggestion, I just don't know.

                N Offline
                N Offline
                Najmal
                wrote on last edited by
                #7

                hi... I know u r a bignner in c#.... So follow up this link... About String Handling

                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