473,770 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Routine to remove extra newline chars and carriage return

I there a quick routine that removes trailing newline chars and
carriage return?

vFlyer Labs
http://www.vflyerlabs.com

May 30 '07 #1
5 13368
You can write one:

String.prototyp e.rtrim = function() {
return this.replace(/\n\r/,"");
}

May 30 '07 #2
On May 29, 8:11 pm, noagbodjivic... @gmail.com wrote:
You can write one:

String.prototyp e.rtrim = function() {
return this.replace(/\n\r/,"");}
String.prototyp e.rtrim = function() {
return this.replace(/[\n\r]/,"");
}

May 31 '07 #3
scripts.contact wrote:
On May 29, 8:11 pm, noagbodjivic... @gmail.com wrote:
You can write one:
String.prototyp e.rtrim = function() {
return this.replace(/\n\r/,"");}

String.prototyp e.rtrim = function() {
return this.replace(/[\n\r]/,"");}
No. The three most common EOLs are:

\n (Linefeed)
\r (Carriage return)
\r\n (Carriage return followed by linefeed)

But you also have:

NEL = Next Line (\u0085)
FF = Form Feed (\u000C)
LS = Line Separator (\u2028)
PS = Paragraph Separator (\u2029)

A fully backwards compatible, Unicode-compliant regexp would be:

/(\r\n|\r|\n|\u0 085|\u000C|\u20 28|\u2029)/g

--
Bart

May 31 '07 #4
On May 31, 2:29 pm, Bart Van der Donck <b...@nijlen.co mwrote:
String.prototyp e.rtrim = function() {
return this.replace(/[\n\r]/,"");}
forgot the $ :
return this.replace(/[\n\r]$/,"");}

A fully backwards compatible, Unicode-compliant regexp would be:

/(\r\n|\r|\n|\u0 085|\u000C|\u20 28|\u2029)/g
/(\r\n|\r|\n|\u0 085|\u000C|\u20 28|\u2029)$/
May 31 '07 #5
On May 31, 2:29 pm, Bart Van der Donck <b...@nijlen.co mwrote:
String.prototyp e.rtrim = function() {
return this.replace(/[\n\r]/,"");}
forgot the $ :
return this.replace(/[\n\r]$/,"");}

A fully backwards compatible, Unicode-compliant regexp would be:

/(\r\n|\r|\n|\u0 085|\u000C|\u20 28|\u2029)/g
/(\r\n|\r|\n|\u0 085|\u000C|\u20 28|\u2029)$/
Jun 1 '07 #6

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

Similar topics

5
7793
by: Tobiah | last post by:
This is a stumbling block for me. Is there a better way to output *just* what I want? I want the output "foobar" >>> print "foo"; print "bar" foo bar >>> print "foo",; print "bar"
5
1820
by: Ron | last post by:
Greetings, I am writing text to a multi line textbox on a timer as follows: txt1.AppendText(@"/* " + DateTime.Now.ToString() + "\n"); Here is what gets displayed /* 1/1/2004 11:12:11 AM|
8
13045
by: John Grandy | last post by:
in VB.NET you can do sb = New StringBuilder("Hello") sb.Append(vbCrLf) What is the C# analogy to vbCrLf ?
34
4116
by: Registered User | last post by:
Hi experts, I'm trying to write a program that replaces two or more consecutive blanks in a string by a single blank. Here's what I did: #include <stdio.h> #include <string.h> #define MAX 80
2
7161
by: Mike P | last post by:
How do you remove all chars such as carriage return and new line from a particular field for all records in a dataset? *** Sent via Developersdex http://www.developersdex.com ***
0
1158
by: John Smith | last post by:
Hi, I am using XML XSL to create a CSV file using Transformation. But during the transformation all the Newline characters (CHR 10) is getting translated to Carriage Return and New Line (CHR 13 and CHR 10) causing problems in the display. Is there are any way to resolve this issue?
4
27832
by: whitej77777 | last post by:
I am trying to write a user defined function that will allow me to strip off the last carriage return and line feed from a text field. We have address fields stored in a text field for our ERP system and some of them have an extra carriage return and line feed at the end of them. This causes havoc when we sync between our ERP system and CRM system. If anyone knows a way to solve this problem the help would be appreciated. Examples:...
7
22987
by: newbtemple | last post by:
Hey all. I'm having a bugger of a time trying to remove carriage returns. I have a large text file with a bunch of little squares. I'm guessing they're carriage returns from what i've googled. They are not standard ascii characters. Anywho, i'de like to get rid of them. I've got a loop that tests this condition: If textCharArray((charPosition) + (133 * rowPosition)) = Environment.NewLine Then textCharArray((charPosition) + (133 *...
4
37266
by: lilly07 | last post by:
I am trying to remove all white spaces, tabs, newline, carriage return etc.. from a text file to make it as a one continous string. But the following code doesnot work. The file size is relatively smaller and hence I didn't use FILE::slurp. Please let me know the problem. Thanks. #!/usr/bin/perl local $/=undef; open(FILE, "test.fa") || die ("Error\n"); $string = <FILE>; $corrected_string =~ s/\n\r\t\s//g;
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9910
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.