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. carriage return

carriage return

Scheduled Pinned Locked Moved C#
tutorial
14 Posts 6 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.
  • L Lost User

    \r\n works in C# (meaning that it produces a carriage return and a newline), what's the problem?

    G Offline
    G Offline
    genieabdo
    wrote on last edited by
    #5

    public void initest(string par==D, int val==1) { TxFrame = par + val; TxFrame += "\r\n"; // the problem is the result of TxFrame is "D1\r\n" m_ComPort.Write(TxFrame); } thanks

    L B 2 Replies Last reply
    0
    • G genieabdo

      public void initest(string par==D, int val==1) { TxFrame = par + val; TxFrame += "\r\n"; // the problem is the result of TxFrame is "D1\r\n" m_ComPort.Write(TxFrame); } thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #6

      Ok, well then what do you want the result to be? Or do you mean that you see "\r\n" in the debugger and thought that it meant backslash r backslash n?

      G 2 Replies Last reply
      0
      • L Lost User

        Ok, well then what do you want the result to be? Or do you mean that you see "\r\n" in the debugger and thought that it meant backslash r backslash n?

        G Offline
        G Offline
        genieabdo
        wrote on last edited by
        #7

        yes I see him in the debug and I want it to be a carriage return

        1 Reply Last reply
        0
        • L Lost User

          Ok, well then what do you want the result to be? Or do you mean that you see "\r\n" in the debugger and thought that it meant backslash r backslash n?

          G Offline
          G Offline
          genieabdo
          wrote on last edited by
          #8

          yes I see him in the debug and I want it to be a carriage

          L 1 Reply Last reply
          0
          • G genieabdo

            Here I would like to know how to do a carriage return in C #, the equivalent of \ r \ n public void initest(string par, int val) { TxFrame = par + val; TxFrame += "\r\n"; m_ComPort.Write(TxFrame); }

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

            There are a few problems with your message: 1. "carriage return" and "line feed" are the names of two popular ASCII characters. 2. what you want to terminate a line of text and start a new one is called "NewLine" in .NET; it is a string and its content depends on your system (Windows, Linux, ...). The default value can be found in Environment.NewLine and will be used by some WriteLine methods, such as Console.WriteLine 3. data sent to a peripheral using a COM port, or sent to another system in some other way (e,g, portable file), or shared with another system (e.g. a database), should NOT rely on a local convention or characteristic. 4. the SerialPort also offers a WriteLine method, which relies on its own NewLine property which in turn is initialized to a "line feed". If you explicitly set to "\r\n", you will probably get what you want. 5. the code in your other message, with initializers D and 1, will not compile as is. 6. code snippets should preserve their formatting, that is what PRE tags are invented for. Use them! 7. If you hope to be successful in programming, you'll have to become a lot more meticulous. :)

            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).


            1 Reply Last reply
            0
            • G genieabdo

              yes I see him in the debug and I want it to be a carriage

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #10

              Don't worry, it's probably already correct - that's just the way these things are displayed in the debugger

              G 1 Reply Last reply
              0
              • L Lost User

                No offense, but I think that's a bad idea in this case - he appears to be using a COM port, and writing something platform dependent to it does not seem like a good idea to me.

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #11

                Ah - I hadn't noticed the COM port usage there. You're right that this doesn't make sense in this case.

                "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                My blog | My articles | MoXAML PowerToys | Onyx

                1 Reply Last reply
                0
                • L Lost User

                  Don't worry, it's probably already correct - that's just the way these things are displayed in the debugger

                  G Offline
                  G Offline
                  genieabdo
                  wrote on last edited by
                  #12

                  thanks

                  1 Reply Last reply
                  0
                  • G genieabdo

                    Here I would like to know how to do a carriage return in C #, the equivalent of \ r \ n public void initest(string par, int val) { TxFrame = par + val; TxFrame += "\r\n"; m_ComPort.Write(TxFrame); }

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

                    Why not something like:

                    m_ComPort.NewLine = "\r\n" ;
                    ...
                    m_ComPort.WriteLine ( System.String.Format ( "{0}{1}" , par , val ) ) ;

                    1 Reply Last reply
                    0
                    • G genieabdo

                      public void initest(string par==D, int val==1) { TxFrame = par + val; TxFrame += "\r\n"; // the problem is the result of TxFrame is "D1\r\n" m_ComPort.Write(TxFrame); } thanks

                      B Offline
                      B Offline
                      Brent_JR
                      wrote on last edited by
                      #14

                      I've had to do a bit of work printing to serial printers and instead of sending the string value to the COM port, you might want to use something along the lines of System.Text.Encoding.UTF8.GetBytes(string) for TxFrame and then append the CR (0x0D) LF (0x0A) to the byte array. It seemed to work for me.

                      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