vbCrLf

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    #1

    vbCrLf

    How can you in vb.net write vbCrLf to a file without using the
    visualbasic namespace?

    In C# you would just case 10/13 to char and right that. I can't seem to
    do that in vb.

    Chris
  • Josip Medved

    #2
    Re: vbCrLf

    How can you in vb.net write vbCrLf to a file without using the
    visualbasic namespace?
    In C# you would just case 10/13 to char and right that. I can't seem to
    do that in vb.
    Use Environment.New Line instead. If you wish, you can do
    Convert.ToChar( number) thing also.

    --
    Greetings,
    Josip Medved,
    A personal website dedicated to technology, software development, and practical tools.


    Comment

    • Andrew Morton

      #3
      Re: vbCrLf

      Chris wrote:
      How can you in vb.net write vbCrLf to a file without using the
      visualbasic namespace?
      Environment.New Line might work for you (especially if you want it to change
      when run in a different environment some time in the future).
      In C# you would just case 10/13 to char and right that. I can't seem
      to do that in vb.
      I suspect you meant 13/10 because CR=13 and LF=10.

      Const CRLF As String = Chr(13) & Chr(10)

      Andrew


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: vbCrLf

        "Chris" <no@spam.comsch rieb:
        How can you in vb.net write vbCrLf to a file without using the visualbasic
        namespace?
        Why would you want to use Visual Basic without actually using it?

        'vbCrLf' or 'ControlChars.C rLf' are part of the Visual Basic Runtime
        Library. This library is always referenced in VB projects and the reference
        cannot be removed for good reasons.

        Instead of writing 'string s = "Hello\r\nWorld "' in C# you can write 'Dim s
        As String = "Hello" & ControlChars.Cr Lf & "World"' in VB without any bad
        implications on runtime performance. The compiler will find out that
        "Hello", 'ControlChars.C rLf', and "World" are constant string literals and
        will emit the concatenated string to the binary when compiling.

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: vbCrLf

          "Josip Medved" <jmedved@jmedve d.comschrieb:
          >How can you in vb.net write vbCrLf to a file without using the
          >visualbasic namespace?
          >
          >In C# you would just case 10/13 to char and right that. I can't seem to
          >do that in vb.
          >
          Use Environment.New Line instead. If you wish, you can do
          Convert.ToChar( number) thing also.
          Both are not exactly the same as "\r\n" in C#. 'Environment.Ne wLine'
          returns the system's new line character sequence, which may differ on
          different operating systems. Thus the compiler cannot perform certain
          optimizations, which is not necessarily a disadvantage if the
          platform-sensitivity of the new line character sequence is required. I
          would also use 'ChrW' instead of 'Convert.ToChar ' because it will enable the
          VB compiler to perform optimizations.

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

          Comment

          • Josip Medved

            #6
            Re: vbCrLf

            Use Environment.New Line instead. If you wish, you can do
            Convert.ToChar( number) thing also.
            would also use 'ChrW' instead of 'Convert.ToChar ' because it will enable the
            VB compiler to perform optimizations.
            ChrW is part of VisualBasic namespace if I remember correctly. Question
            was
            "How can you in vb.net write vbCrLf to a file without using the
            visualbasic
            namespace?"

            --
            Greetings,
            Josip Medved
            A personal website dedicated to technology, software development, and practical tools.


            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: vbCrLf

              "Josip Medved" <jmedved@jmedve d.comschrieb:
              Use Environment.New Line instead. If you wish, you can do
              Convert.ToChar( number) thing also.
              >
              >would also use 'ChrW' instead of 'Convert.ToChar ' because it will enable
              >the
              >VB compiler to perform optimizations.
              >
              ChrW is part of VisualBasic namespace if I remember correctly. Question
              was
              "How can you in vb.net write vbCrLf to a file without using the
              visualbasic
              namespace?"
              Yep, but why would you want to write code in VB without using features of VB
              if those features are superior over the features provided by the .NET
              Framework's class library? I am questioning the OP's goal because it does
              not make sense to me.

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

              Comment

              • Josip Medved

                #8
                Re: vbCrLf

                Yep, but why would you want to write code in VB without using features of VB
                if those features are superior over the features provided by the .NET
                Framework's class library? I am questioning the OP's goal because it does
                not make sense to me.
                I have no idea why he wants to do that. :)
                He just said that he wants it.

                BTW. I would not say that it is superior. Just friendlier.

                --
                Greetings,
                Josip Medved
                A personal website dedicated to technology, software development, and practical tools.


                Comment

                • Phill W.

                  #9
                  Re: vbCrLf

                  Chris wrote:
                  How can you in vb.net write vbCrLf to a file without using the
                  visualbasic namespace?
                  Lots of good answers from others but I'll chip this in anyway:

                  /Why/ do you want to do this?
                  The only reason I can think of is that you want to avoid any dependency
                  on Microsoft.Visua lBasic.dll. Well, if you're writing in Visual Basic,
                  you can't. The Visual Basic compiler builds code that makes calls into
                  MS.VB and, if you go to the *tremendous* lengths required to avoid
                  these, what you wind up with won't look /anything/ like Basic (and will
                  probably run slower as well).
                  In C# you would just case 10/13 to char and right that. I can't seem to
                  do that in vb.
                  AFAIK, you can't /cast/ an integer into a character, you have to
                  /convert/ it - C wraps this up in the same syntax for you; Visual Basic
                  doesn't.

                  Convert.ToChar

                  should get you close.

                  Or CChar, of course ;-))

                  Regards,
                  Phill W.

                  Comment

                  Working...