VBCRLF in C#

C

Chad Myers

Murali:

Like José said, Environment.NewLine is
the best way for general use.

In certain circumstances (writing files for other
platforms) it's necessary to control how a newline
is created.

Environment.NewLine basically returns a
Carriage Return (CR, 0x13) and a
Linefeed(LF, 0x10). Carriage return moves the
cursor back to column 0, and Linefeed moves
the cursor to the next row.

Windows generally uses CRLF to represent a
new line. Unix/Linux just uses LF, and
MacOS used to use CR. Now adays, most
platforms can use anything, but if you
open a Unix file in Notepad, for example,
you won't see the line breaks, everything
will be on one line.

In C#, you can represent these special
characters as "escape" characters. For
example, \r is CR, \n LF, \t TAB, \0 null,
etc.

If you want a CRLF in your string, you'd
do this:

string foo = "This is some text\r\nNew Line!";

But for the cases where you don't need
a special platform specific code, use
Environment.NewLine.

-c
 
M

Murali Inguva

Thanks for your information
Coud you please let me for VBTab Also
I dont want like "\t".
 
M

Murali Inguva

Thanks for your information
Coud you please let me for VBTab Also
I dont want like "\t".
 
J

Jon Skeet

Murali Inguva said:
Coud you please let me for VBTab Also
I dont want like "\t".

What do you mean by you 'dont want like "\t"' exactly?

\t *is* how tab is escaped in C#. So a line with a tab in it might be
something like:

string x = "first bit\tsecond bit";

You can always make your own name for that if you want:

const string Tab="\t";

and then use

string x = "first bit" + Tab + "second bit";
 
C

Chad Myers

I'm sorry, I don't understand your English,
I'm not sure what you're asking.

You don't like \t and you want a different
way to make a tab? I'm not sure there is
a way.

0x9 is the tab char, you could do something
like:

string foo = ((char)9) + "Intended text";

But I think that this looks much better:

string foo = "\tIndented text";

but that's just me :)

-c
 
C

Chad Myers

Jon Skeet said:
You can always make your own name for that if you want:

const string Tab="\t";

and then use

string x = "first bit" + Tab + "second bit";

How bout csTab? ;)

-c
 

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

Similar Threads


Top