Tech Off Thread

13 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Remove Carriage Return chars

Back to Forum: Tech Off
  • User profile image
    Shark_M

    Hi guys

    when someone presses the Enter key in their keyboard, there is a carriage return chars that exist , but you cant see them at debug time. I want to check if the input was not nothing

    meaning if the input is not just enter, and if its not a space, and if its not a carriage return chars like "r\n\" or "\r\n\r"

    So i did the following

    Trim(Replace(Replace(Me.txtSend.Text.ToString(), "\r\n", String.Empty), vbCrLf, String.Empty))

    Dim S as String = Trim(Replace (txtInput.Text.ToString(),"\r\n\",String.Empty))
     if  S <> string.empty and S.Length > 0 then
        process message... here
    end if


    But its not working... i dont know why?

  • User profile image
    JohnAskew



    strText.Replace("\n", "");

    C#

  • User profile image
    Shark_M

    did not work, still same

    I made this Msgbox "(" + text + ")"

    and the message box came like this
    (
    )

    and not like ()

    so there must be a linefeed char in there, but i cant see it or remove it

  • User profile image
    Shark_M

    I fixed it using Chr(10)

    I replaced Chr (10) with string.empty

    and it worked


    apparently chr(10) = line feed and Chr(13) = carriage return

    two different things

  • User profile image
    Jorgie

    Yep, from the old printer days we have:

    \r = carriage return but stay on same line; chr(13)
    \n = line feed but no flush left; chr(10)

    DOS text files use \r\n
    UNIX text files use \n
    MAC OS9 I think used \r

    Some terminals use chr(10) for the "enter" key and some use chr(13).

    I use this to get both:

    string x = "\r or \n or \r\n";
    string y = x.replace("\n","").replace("\r","");

    If you use regex be careful because in standard (perl style) regex the '.' (period) matches all characters EXCEPT the currently defined line ending. In perl that means you must use /s to tell regex to let '.' match line endings which also makes ^ and $ only match at the actually begining and end of the string, not the begining and end of each line.

    I do not have C# regex stuff all figured out so good luck with that!

    Jorgie

  • User profile image
    gregoryw

    To make things clearer in your code, you could use:

    Microsoft.VisualBasic.ControlChars.Cr

    or

    Microsoft.VisualBasic.ControlChars.Lf

  • User profile image
    Minh

    Shark_M wrote:
    meaning if the input is not just enter, and if its not a space, and if its not a carriage return chars like "r\n\" or "\r\n\r"

    Correct me if I'm wrong, but "\n" or other slash chars are C# only. As someone already mentioned, you should use the enumerations.

  • User profile image
    Rossj

    Msgbox "(" + text.Trim() + ")"

    Trim will remove the following from the beginning and end of the text.

    Unicode name

    Unicode code point

    CHARACTER TABULATION

    U+0009

    LINE FEED

    U+000A

    LINE TABULATION

    U+000B

    FORM FEED

    U+000C

    CARRIAGE RETURN

    U+000D

    SPACE

    U+0020

    NO-BREAK SPACE

    U+00A0

    EN QUAD

    U+2000

    EM QUAD

    U+2001

    EN SPACE

    U+2002

    EM SPACE

    U+2003

    THREE-PER-EM SPACE

    U+2004

    FOUR-PER-EM SPACE

    U+2005

    SIX-PER-EM SPACE

    U+2006

    FIGURE SPACE

    U+2007

    PUNCTUATION SPACE

    U+2008

    THIN SPACE

    U+2009

    HAIR SPACE

    U+200A

    ZERO WIDTH SPACE

    U+200B

    IDEOGRAPHIC SPACE

    U+3000

    ZERO WIDTH NO-BREAK SPACE

    U+FEFF


  • User profile image
    Tensor

    gregoryw wrote:
    To make things clearer in your code, you could use:

    Microsoft.VisualBasic.ControlChars.Cr

    or

    Microsoft.VisualBasic.ControlChars.Lf


    At the risk of being laughed out of the room by the c# types, you could even use vbcr or vblf, which both still work in vb.net.

  • User profile image
    Minh

    Tensor wrote:
    gregoryw wrote:To make things clearer in your code, you could use:

    Microsoft.VisualBasic.ControlChars.Cr

    or

    Microsoft.VisualBasic.ControlChars.Lf


    At the risk of being laughed out of the room by the c# types, you could even use vbcr or vblf, which both still work in vb.net.

    Ha! ha! Get out of here! Non-OO compiler constants? Oh, you VB types! Ha! ha!

  • User profile image
    defstream

    Minh wrote:
    Tensor wrote:
    gregoryw wrote:To make things clearer in your code, you could use:

    Microsoft.VisualBasic.ControlChars.Cr

    or

    Microsoft.VisualBasic.ControlChars.Lf


    At the risk of being laughed out of the room by the c# types, you could even use vbcr or vblf, which both still work in vb.net.

    Ha! ha! Get out of here! Non-OO compiler constants? Oh, you VB types! Ha! ha!


    Thank god for System.Environment.NewLine, language independent.

  • User profile image
    dotnetjunkie

    defstream wrote:
    Minh wrote:
    Tensor wrote:
    gregoryw wrote: To make things clearer in your code, you could use:

    Microsoft.VisualBasic.ControlChars.Cr

    or

    Microsoft.VisualBasic.ControlChars.Lf


    At the risk of being laughed out of the room by the c# types, you could even use vbcr or vblf, which both still work in vb.net.

    Ha! ha! Get out of here! Non-OO compiler constants? Oh, you VB types! Ha! ha!


    Thank god for System.Environment.NewLine, language independent.


    And above all platform / OS independent !

  • User profile image
    Sven Groot

    dotnetjunkie wrote:
    And above all platform / OS independent !

    In VB there's also ControlChars.NewLine which serves the same purpose. Just in case you want to be platform neutral but really like ControlChars anyway.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.