473,568 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Removing carriage return/line field from a string


Hi

What's the regex to remove the carriage return/line field from a string?
These can occur multiple times in the string as in xxx\r\n\r\n.

--

John Dalberg
Nov 17 '05 #1
2 38752
Use
myString = myString.Replac e(System.Enviro nment.NewLine, string.Empty);

System.Environm ent.NewLine is more portable than "\r\n", and Replace is
*far* faster than a regular expression.

"John Dalberg" <jo*****@hotmai l.com> wrote in message
news:da******** *************** ****@40tude.net ...

Hi

What's the regex to remove the carriage return/line field from a string?
These can occur multiple times in the string as in xxx\r\n\r\n.

--

John Dalberg

Nov 17 '05 #2
John Dalberg wrote:
Hi

What's the regex to remove the carriage return/line field from a string?
These can occur multiple times in the string as in xxx\r\n\r\n.


Warning: untested code.

Simple (but possibly a bit expensive):

string RemoveAndNewlin eLineFeed(strin g s) {
char[] lf = {'\r', '\n'};
return string.Join("", string.Split(s, lf));
}

Note that (according to string.Split docs):
RemoveNewlineAn dLineFeed("a\rb \nc\r\nd\n\re\r \r\n\r\n").Equa ls("abcde").

--
Helge Jensen
mailto:he****** ****@slog.dk
sip:he********* *@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #3

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

Similar topics

0
1774
by: raj | last post by:
I have multiline-text box in my C# application. User enter text into the multiline-text box, and without completing the whole line, user press Enter Key and go to the next line, by leaving the '\n'(new line character) in the string. I use this text to write to a database field and then write that field to an excel file. The string is not...
3
2201
by: JMCN | last post by:
does anyone know how to take out {enter} strings from a field? for instance, i have: "INTWEST ADJUSTMENT ORG ILLINOIS FUND PARTICIPANT DIVIDEND". i managed to take out extra spaces but then it comes to {enter} and {tab} i cannot parse them out. thanks!! jung
2
2937
by: eagleofjade | last post by:
I am trying to import data from a Word document into an Access table with VBA. The Word document is a form which has various fields. One of the fields is a field for notes. In some cases, this note field contains carriage returns. When I import a note field that has carriage returns, what shows up in the Access field are vertical black...
3
26303
by: Smythe32 | last post by:
Hi All, I am trying to remove carriage returns from a text field via some code. Here is an example of what I am up against. The field streetname contains the little square box that I believe is a carriage return. So, the field will have text, the little square box and more text. I
3
10006
by: Gillian Steele | last post by:
I'm trying to import data into a memo field by running an append query. The data is to be imported as if it was entered with separate lines in the memo field. I have tried inserting chr(13)s into the string that is being appended into the memo field but when appended, the data displays with a square box in place of a carriage return/line...
6
13518
by: shajias | last post by:
Hi, I am having a xml code like this <name> I am having a carriage return here. Second line with carriage return. This is the last line. </name>
1
2326
by: cgillett76 | last post by:
Hello, I'm using InfoPath to write data to a accessvdatabase. Once the form has been submitted a VB script runs to create a text file to input to another application. Some of the fields contain carriage returns and I need these replaced by /n. Sub LogChangesV2() Dim qdf As DAO.QueryDef Dim db As DAO.Database Dim rst As DAO.Recordset
4
8372
by: LOCAFO | last post by:
I am using vb.net and have a long string of text. When I use vbnewline or vbCrLf, for a carraige retun, I get a black square box in the SQL database table. I need the carriage return but I don't want the symbol to show up in SQL table because when another application (vb.6) is opened which uses the same SQL dbase table and shows the text, I get...
11
12572
by: evenlater | last post by:
My db allows the user to send email via CDO. The body of the email is determined in code. I have built an email form with To, CC and Subject lines and a large text box for the body of the message so the user can edit the default email message body before sending the message. But when I populate the large text box (txtBody), I can't get it to...
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7916
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
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
5217
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
3651
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
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
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.