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 splitting

String splitting

Scheduled Pinned Locked Moved C#
helpquestion
6 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
    numbers1thru9
    wrote on last edited by
    #1

    I have a string that whenever it finds \r\n in the string i need it to be split, i tried using Text.Split("\r\n") but it doesnt like that. This is the only thing that is causing me errors with my printing, can anyone help me fix this? or does anyone know how i can count the number of times that \r\n appears in a string?

    N M 2 Replies Last reply
    0
    • N numbers1thru9

      I have a string that whenever it finds \r\n in the string i need it to be split, i tried using Text.Split("\r\n") but it doesnt like that. This is the only thing that is causing me errors with my printing, can anyone help me fix this? or does anyone know how i can count the number of times that \r\n appears in a string?

      N Offline
      N Offline
      numbers1thru9
      wrote on last edited by
      #2

      Right after i posted this i had an epiphany, i just replaced \r\n in the string with ` and split using that becasue i i was trying to find an odd character that no one uses very often and that solved my problem

      D 1 Reply Last reply
      0
      • N numbers1thru9

        Right after i posted this i had an epiphany, i just replaced \r\n in the string with ` and split using that becasue i i was trying to find an odd character that no one uses very often and that solved my problem

        D Offline
        D Offline
        Daniel Grunwald
        wrote on last edited by
        #3

        You don't have to reserve a special character, just use text.Replace("\r", "").Split("\n")

        1 Reply Last reply
        0
        • N numbers1thru9

          I have a string that whenever it finds \r\n in the string i need it to be split, i tried using Text.Split("\r\n") but it doesnt like that. This is the only thing that is causing me errors with my printing, can anyone help me fix this? or does anyone know how i can count the number of times that \r\n appears in a string?

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #4

          Hello, Instead, you should use:

          Text.Split(System.Environment.NewLine);

          All the best, Martin

          L 1 Reply Last reply
          0
          • M Martin 0

            Hello, Instead, you should use:

            Text.Split(System.Environment.NewLine);

            All the best, Martin

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

            I do not agree. First of all, System.Environment.NewLine results in a string, but String.Split requires a char or char array. Second, the logic you follow is correct only if the system that generates the file, and the system that processes the file, both have the same opinion on how to terminate lines. e.g. if you generate the file on Linux, and want to process it on WinXP, it would not work. :)

            Luc Pattyn

            M 1 Reply Last reply
            0
            • L Luc Pattyn

              I do not agree. First of all, System.Environment.NewLine results in a string, but String.Split requires a char or char array. Second, the logic you follow is correct only if the system that generates the file, and the system that processes the file, both have the same opinion on how to terminate lines. e.g. if you generate the file on Linux, and want to process it on WinXP, it would not work. :)

              Luc Pattyn

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #6

              I do agree with you in every point.

              Luc Pattyn wrote:

              First of all, System.Environment.NewLine results in a string, but String.Split requires a char or char array.

              I shout test before I post!

              Luc Pattyn wrote:

              Second, the logic you follow is correct only if the system that generates the file, and the system that processes the file, both have the same opinion on how to terminate lines.

              It's not important in the application I'm working on, but it's good to inform about that it's possibility! Thanks All the best, Martin

              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