Using the vbCrLf constant

G

Guest

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.Replace(vbCrLf, chr(10) )

Thanks in advance,
Michael McD

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

Guest

Environment.NewLine 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.NewLine may
not be (although I've never been in an environment where it wasn't).

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter

James Curran said:
What you really want to use is Environment.NewLine.

"(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.McD said:
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.Replace(vbCrLf, chr(10) )

Thanks in advance,
Michael McD

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

Jon Skeet [C# MVP]

David Anton said:
Environment.NewLine 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.NewLine may
not be (although I've never been in an environment where it wasn't).

I would expect Environment.NewLine 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...
 
G

Guest

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top