473,569 Members | 2,880 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 154979
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.co m> 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.co m>
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.Environm ent.NewLine

So...

string str = "line one" + System.Environm ent.NewLine + "line two"

or ...

string str = System.String.F ormat("line 1{0}line 2",
System.Environm ent.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.Environm ent.NewLine

So...

string str = "line one" + System.Environm ent.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.New Line 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.co m>
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****@NOSPAMd ahat.com> wrote in message
news:B8******** *************** ***********@mic rosoft.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
4721
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, but I have a program that created a string of over 25,000 characters (the browser was Konqueror). Are there limits on these lengths? If I require...
2
46826
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, insert the character using insert() and then join them back as string.. thanks
4
5455
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. The correct encoding turned out to be extended ASCII (850). But now I'd like to store the result in a database. I have tried to do this by just...
1
1774
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
38770
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 messages and one of them kept erroring out. I've pretty much determined that it hates the ' character.. and I'm sure it'd hate other special...
6
2990
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
3199
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 line characters in the middle of a line. When the perl script is evaluating each line it meets this new line character and outputs it onto a new line...
1
2897
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 request("submit")="Save" then OpenDataBase conn newshead=request("newshead") newsdes=request("newsdes")
0
1405
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 do this, but have not managed to find anything. I am sure this is possible. I need this to be inserted into the title of my report, pending on the...
1
2699
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 it didn't do anything. So how can I handle these end-of-line characters? I am using python 3. Please help. Object= open('w.txt','r') L=...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6290
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.