Using the vbCrLf constant

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

    Using the vbCrLf constant

    Would anyone know how I might access to the vbCrLf constant.

    I'd like to use teh following bit of VB code in C#:

    strFoo.Text.Rep lace(vbCrLf, chr(10) )

    Thanks in advance,
    Michael McD

    Ps and what id the C# exuivilent of chr(10) is it (char) 10?
  • David Anton

    #2
    RE: Using the vbCrLf constant

    Use \r\n for vbCrLf.

    David Anton
    Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

    Home of the Instant C# VB.NET to C# converter
    and the Instant VB C# to VB.NET converter

    "Michael.Mc D" wrote:
    [color=blue]
    > Would anyone know how I might access to the vbCrLf constant.
    >
    > I'd like to use teh following bit of VB code in C#:
    >
    > strFoo.Text.Rep lace(vbCrLf, chr(10) )
    >
    > Thanks in advance,
    > Michael McD
    >
    > Ps and what id the C# exuivilent of chr(10) is it (char) 10?[/color]

    Comment

    • James Curran

      #3
      Re: Using the vbCrLf constant

      What you really want to use is Environment.New Line.

      "(char) 10" == '\n' == VB's chr(10)

      --
      --
      Truth,
      James Curran
      [erstwhile VC++ MVP]

      Home: www.noveltheory.com Work: www.njtheater.com
      Blog: www.honestillusion.com Day Job: www.partsearch.com

      "Michael.Mc D" <MichaelMcD@dis cussions.micros oft.com> wrote in message
      news:815AF866-0D7F-45EA-B3D9-4F378172C219@mi crosoft.com...[color=blue]
      > Would anyone know how I might access to the vbCrLf constant.
      >
      > I'd like to use teh following bit of VB code in C#:
      >
      > strFoo.Text.Rep lace(vbCrLf, chr(10) )
      >
      > Thanks in advance,
      > Michael McD
      >
      > Ps and what id the C# exuivilent of chr(10) is it (char) 10?[/color]


      Comment

      • tbain

        #4
        RE: Using the vbCrLf constant

        Or use System.Environm ent.Newline.

        "Michael.Mc D" wrote:
        [color=blue]
        > Would anyone know how I might access to the vbCrLf constant.
        >
        > I'd like to use teh following bit of VB code in C#:
        >
        > strFoo.Text.Rep lace(vbCrLf, chr(10) )
        >
        > Thanks in advance,
        > Michael McD
        >
        > Ps and what id the C# exuivilent of chr(10) is it (char) 10?[/color]

        Comment

        • David Anton

          #5
          Re: Using the vbCrLf constant

          Environment.New Line is often a preferable alternative to \r\n, but if you're
          looking at replacing text in a string and you were previously using vbCrLf in
          VB for this operation, then it is better to use the literal equivalent since
          \r\n will definitely always be equal to vbCrLf while Environment.New Line may
          not be (although I've never been in an environment where it wasn't).

          David Anton
          Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

          Home of the Instant C# VB.NET to C# converter
          and the Instant VB C# to VB.NET converter

          "James Curran" wrote:
          [color=blue]
          > What you really want to use is Environment.New Line.
          >
          > "(char) 10" == '\n' == VB's chr(10)
          >
          > --
          > --
          > Truth,
          > James Curran
          > [erstwhile VC++ MVP]
          >
          > Home: www.noveltheory.com Work: www.njtheater.com
          > Blog: www.honestillusion.com Day Job: www.partsearch.com
          >
          > "Michael.Mc D" <MichaelMcD@dis cussions.micros oft.com> wrote in message
          > news:815AF866-0D7F-45EA-B3D9-4F378172C219@mi crosoft.com...[color=green]
          > > Would anyone know how I might access to the vbCrLf constant.
          > >
          > > I'd like to use teh following bit of VB code in C#:
          > >
          > > strFoo.Text.Rep lace(vbCrLf, chr(10) )
          > >
          > > Thanks in advance,
          > > Michael McD
          > >
          > > Ps and what id the C# exuivilent of chr(10) is it (char) 10?[/color]
          >
          >
          >[/color]

          Comment

          • Jon Skeet [C# MVP]

            #6
            Re: Using the vbCrLf constant

            David Anton <DavidAnton@dis cussions.micros oft.com> wrote:[color=blue]
            > Environment.New Line is often a preferable alternative to \r\n, but if you're
            > looking at replacing text in a string and you were previously using vbCrLf in
            > VB for this operation, then it is better to use the literal equivalent since
            > \r\n will definitely always be equal to vbCrLf while Environment.New Line may
            > not be (although I've never been in an environment where it wasn't).[/color]

            I would expect Environment.New Line to be "\n" when running Mono on
            Linux. Now, given the number of people who probably *assume* it to be
            "\r\n", the Mono project is in a difficult position - it definitely
            *should* be "\n" as that's the Unix platform's normal newline, but I
            suspect that introduces bugs into the code of various applications...

            --
            Jon Skeet - <skeet@pobox.co m>
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            If replying to the group, please do not mail me too

            Comment

            • David Anton

              #7
              Re: Using the vbCrLf constant

              Exactly. So if you were looking for the literal string represented by vbCrLf
              in VB, you had better look for \r\n in C# (since vbCrLf is always \r\n on any
              system).

              On the other hand, if your original VB code was looking for the newline on
              the current system running the app, then you had better look for
              Environment.New Line.
              Unfortunately, from our point of view (Instant C#) there's no way to
              determine which of these is appropriate (although we do provide the option of
              converting either of the two ways across an entire conversion).

              "Jon Skeet [C# MVP]" wrote:
              [color=blue]
              > David Anton <DavidAnton@dis cussions.micros oft.com> wrote:[color=green]
              > > Environment.New Line is often a preferable alternative to \r\n, but if you're
              > > looking at replacing text in a string and you were previously using vbCrLf in
              > > VB for this operation, then it is better to use the literal equivalent since
              > > \r\n will definitely always be equal to vbCrLf while Environment.New Line may
              > > not be (although I've never been in an environment where it wasn't).[/color]
              >
              > I would expect Environment.New Line to be "\n" when running Mono on
              > Linux. Now, given the number of people who probably *assume* it to be
              > "\r\n", the Mono project is in a difficult position - it definitely
              > *should* be "\n" as that's the Unix platform's normal newline, but I
              > suspect that introduces bugs into the code of various applications...
              >
              > --
              > Jon Skeet - <skeet@pobox.co m>
              > http://www.pobox.com/~skeet
              > If replying to the group, please do not mail me too
              >[/color]

              Comment

              Working...