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. multiple lines string

multiple lines string

Scheduled Pinned Locked Moved C#
question
5 Posts 4 Posters 2 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.
  • U Offline
    U Offline
    User 589870
    wrote on last edited by
    #1

    i have to check if my string span to more than one lines than append space at start of each line..hw can this be done? Regards Ali

    A 1 Reply Last reply
    0
    • U User 589870

      i have to check if my string span to more than one lines than append space at start of each line..hw can this be done? Regards Ali

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      It would be great if you give some example so that I can give you proper solution. Thanks !

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      U 1 Reply Last reply
      0
      • A Abhijit Jana

        It would be great if you give some example so that I can give you proper solution. Thanks !

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

        U Offline
        U Offline
        User 589870
        wrote on last edited by
        #3

        dr[i - 1] = " " + fieldValues[i].ToString(); this is my code...it only appends space at first line of string but if string spans multiple lines hw to append space at start of each line.

        N E 2 Replies Last reply
        0
        • U User 589870

          dr[i - 1] = " " + fieldValues[i].ToString(); this is my code...it only appends space at first line of string but if string spans multiple lines hw to append space at start of each line.

          N Offline
          N Offline
          Nicholas Butler
          wrote on last edited by
          #4

          You have to split the original string at new lines, add the space and then Join them together again. This is an example:

          string original = ...;

          string spaced = String.Join( "\n", original.Split( '\n' ).Select( s => " " + s ).ToArray() );

          Nick

          ---------------------------------- Be excellent to each other :)

          1 Reply Last reply
          0
          • U User 589870

            dr[i - 1] = " " + fieldValues[i].ToString(); this is my code...it only appends space at first line of string but if string spans multiple lines hw to append space at start of each line.

            E Offline
            E Offline
            Eric Dahlvang
            wrote on last edited by
            #5

            dr[i - 1] = " " + fieldValues[i].Replace("\n","\n ");

            --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

            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