473,507 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to insert new line, other characters in a string?

In VB, I would do this for a new line:

str = "text here" & VbCrLf & "more text"

For other characters, I would use the ascii code:

For example, Chr(34) is a double quote (").

how do I do this kind of stuff in C#?

Can anyone point me to a reference?

Thanks!
Nov 17 '05 #1
7 154974
CrLf stands for Control Return and Line Feed... two characters that you can
individually specify with a couple of escape characters, namely \r and \n
respectively, so for your example you would use:

str = "text here" + "\r\n" + "more text"

Brendan
"deko" wrote:
In VB, I would do this for a new line:

str = "text here" & VbCrLf & "more text"

For other characters, I would use the ascii code:

For example, Chr(34) is a double quote (").

how do I do this kind of stuff in C#?

Can anyone point me to a reference?

Thanks!

Nov 17 '05 #2
There are 11 predefined literals:

\’ single quote
\" double quote
\\ backslash
\0 null character
\a alert
\b backspace
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab

For others, use the Unicode value '\uXX'

Mark
Nov 17 '05 #3
deko <de**@nospam.com> wrote:
In VB, I would do this for a new line:

str = "text here" & VbCrLf & "more text"

For other characters, I would use the ascii code:

For example, Chr(34) is a double quote (").

how do I do this kind of stuff in C#?

Can anyone point me to a reference?


See http://www.yoda.arachsys.com/csharp/faq/#escapes

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
KH
The .NET equivelant to vbCrLf is System.Environment.NewLine

So...

string str = "line one" + System.Environment.NewLine + "line two"

or ...

string str = System.String.Format("line 1{0}line 2",
System.Environment.NewLine)

"deko" wrote:
In VB, I would do this for a new line:

str = "text here" & VbCrLf & "more text"

For other characters, I would use the ascii code:

For example, Chr(34) is a double quote (").

how do I do this kind of stuff in C#?

Can anyone point me to a reference?

Thanks!

Nov 17 '05 #5
KH <KH@discussions.microsoft.com> wrote:
The .NET equivelant to vbCrLf is System.Environment.NewLine

So...

string str = "line one" + System.Environment.NewLine + "line two"


Well, that's the equivalent in .NET, but it's not guaranteed to be the
equivalent on all CLI implementations.

vbCrLf is (as the name suggests) carriage return / line feed - "\r\n".

Environment.NewLine is the normal new line sequence *for the
environment of the CLI*. On Linux, for instance, that's probably \n.

Sometimes you should use the normal environment version, other times
(particularly when following standards) you should use precise values
which won't be environmentally dependent.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
> There are 11 predefined literals:

\' single quote
\" double quote
\\ backslash
\0 null character
\a alert
\b backspace
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab

For others, use the Unicode value '\uXX'


Great! Armed with this and the reference sheet at
http://www.unicode.org/charts/ I'm off to the races...

And I just learned that my alphabet is "Basic Latin".... you mean there are
others? ;)
Nov 17 '05 #7

"Brendan Grant" <gr****@NOSPAMdahat.com> wrote in message
news:B8**********************************@microsof t.com...
CrLf stands for Control Return and Line Feed... two characters that you
can
individually specify with a couple of escape characters, namely \r and \n
respectively, so for your example you would use:

str = "text here" + "\r\n" + "more text"

Brendan
"deko" wrote:
In VB, I would do this for a new line:

str = "text here" & VbCrLf & "more text"

For other characters, I would use the ascii code:

For example, Chr(34) is a double quote (").

how do I do this kind of stuff in C#?

Can anyone point me to a reference?

Thanks!


And instead of concatenating the strings, make it one string (Although, with
literals, the compiler will do it for you):

str = "text here\r\nmore text";

:)

Mythran

Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4720
by: Hal Vaughan | last post by:
Is there a maximum length for Javascript program lines? What about strings? Is there a limit on string length? I found some references that said the maximum string length was 256 characters,...
2
46816
by: eight02645999 | last post by:
hi is there a string method to insert characters into a string? eg str = "abcdef" i want to insert "#" into str so that it appears "abc#def" currently what i did is convert it to a list,...
4
5451
by: jcsnippets.atspace.com | last post by:
Hi everyone, Recently I have posted a question regarding special characters in text files. I was trying to read the text file to process the text later on, but I was using the wrong encoding....
1
1769
by: paul.hester | last post by:
Hi all, Does anyone have a good regular expression to strip tab and new line characters in the Render method? Thanks, Paul
3
38765
by: Arielle | last post by:
Greetings! I'm using classic ASP and an insert statement to save bulletin messages to a database that can be updated or viewed later. At first I thought it worked perfectly so I took some sample...
6
2977
by: Steve | last post by:
I'm getting a string such as name1\r\nname2 how can I remove the \r\n and just have the string as name1 name2?
0
3191
by: coco09 | last post by:
Hi all I have the following line of text in my script $var = do {local $/; <$FILE>};#<-- slurp whole file in scalar The problem i am having is that the input file is a pcl file and has new...
1
2893
by: rajivkadam420 | last post by:
how to insert special characters into ms acess database along with text below is my example <!--#include file="common.asp"--> <!--#include file="header.asp"--> <% CheckAdminLogin if...
0
1400
by: midhun singh | last post by:
Hi all, I have a little bit of a problem figuring out how to insert a textbox string from a VB.Net Windows form onto a Crystal Report. I have search through many articles and manuals for a way to...
1
2694
by: nana pink | last post by:
I am trying to read from a txt file and counts the number of times each word appears. The problem is that it counts the EOL characters as well. I want to skip them. I tried to use the rstrip, still...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.