newline

How do I handle newlines in json?

I've generated some JSON and I'm trying to pull it into an object in javascript and I keep getting errors. Here's what I have: var data = '{"count" : 1, "stack" : "sometext\n\n"}'; var dataObj = eval('('+data+')'); This gives me an error: unterminated string literal When I take out the \n after sometext the error goes away. I ca...

How can I replace newline characters using JSP and JSTL?

I have a list of bean objects passed into my JSP page, and one of them is a comment field. This field may contain newlines, and I want to replace them with semicolons using JSTL, so that the field can be displayed in a text input. I have found one solution, but it's not very elegant. I'll post below as a possibility. ...

'^M' character at end of lines

When I run a particular SQL script in Unix environments, I'm am seeing a '^M' character at the end of each line of the SQL script as it is echoed to the command-line. I don't know on which OS the SQL script was originally created. What is causing this and how do I fix it? ...

how do you search for files containing dos line endings (CRLF) with grep under linux?

something like grep -IUr --color '\r\n' . the above seems to match for literal 'rn' which is not what is desired the output of this will be piped through xargs into todos to convert crlf to lf like this grep -IUrl --color '^M' . | xargs -ifile fromdos 'file' ...

using fstream to read every character including spaces and newline

I wanted to use fstream to read a txt file. I am using inFile >> characterToConvert, but the problem is that this omits any spaces and newline. I am writing an encryption program so i need to include the spaces and newlines and was wondering what would be the proper way to go about accomplishing this. Thanks in advance, Tomek ...

Automatic newlines and formatting for blogging software

I'm writing by own blogging engine in PHP with a MYSQL backend database. MY question is: How would you go about making user comments and blog posts include newlines wherever they are appropriate? For example, if a user hits the return key in the message/comments box how would this translate into a new line that would show in the browser...

How do I format a String in an email so Outlook will print the line breaks?

I'm trying to send an email in Java but when I read the body of the email in Outlook, it's gotten rid of all my linebreaks. I'm putting \n at the ends of the lines but is there something special I need to do other than that? The receivers are always going to be using Outlook. I found a page on microsoft.com that says there's a 'Remove ...

newline character(s)

Does your software handle newline characters from other systems? Linux/BSD linefeed ^J 10 x0A Windows/IBM return linefeed ^M^J 13 10 x0D x0A old Macs return ^M 13 x0D others? For reasons of insanity, I am going with using the Linux version of the newline character in my text files. But, when...

Pass a PHP string to a Javascript variable (including escaping newlines)

What is the easiest way to encode a PHP string for output to a Javascript variable? I have a PHP string which includes quotes and newlines. I need the contents of this string to be put into a Javascript variable. Normally, I would just construct my Javascript in a PHP file, ala: <script> var myvar = "<?php echo $myVarValue;?>"; </s...

What's the best CRLF handling strategy with git?

I tried committing files with CRLF-ending lines but it failed. I spent a whole work day on my Windows computer trying different strategies, and was almost drawn to stop trying to use git and instead try mercurial. Please share only one best practice per answer. ...

Python find() and newlines

While editing someone else's abandoned Python script, I was trying to use mystring.find("\n", i) to get the index of the next newline in a string. But this consistently returns -1 (even when I try using "\r\n" instead of "\n"). I know there are newlines in the string, because I had just loaded it from a file. I am not very familiar wi...

How do I include a newline character in a string in Delphi?

I want to create a string that spans multiple lines to assign to a Label Caption property. How is this done in Delphi? ...

How can I remove (chomp) a newline in Python?

This is one of my most common questions when I am coding Python (I was fed Perl as a baby and am forever trying to get rid of that affliction) and I wanted to put it out there on stack overflow so that next time I search for 'chomp python' on google, I get a useful answer. ...

How can I join lines in a CSV file when one of the fields has a newline?

If I have a comma separated file like the following: foo,bar,n ,a,bc,d one,two,three ,a,bc,d And I want to join the \n, to produce this: foo,bar,n,a,bc,d one,two,three,a,bc,d What is the regex trick? I thought that an if (/\n,/) would catch this. Also, will I need to do anything special for a UTF-8 encoded file? Finally, a sol...

MSXML and newline normalization(?) of Document.xml property

I created following simple xml (C escape sequence used) "<A>\n</A>" When MSXML (v4 and v6) serialize DOM document using IXMLDOMDocument2.xml it changes newline to dos format and returns: "<A>\r\n</A>" instead. When I use DOM to retrieve only string node inside element I get correct single character ("\n") string. Of course I have pres...

How do i remove all linebreaks using XSLT?

I have something like this: <node TEXT=" txt A "/> <node TEXT=" txt X "/> <node> <html> <p> txt Y </p> </html> </node> <node TEXT="txt B"/> and i want to use XSLT to get this: txt A txt X txt Y txt B I want to strip all useless whitespaces and linebreaks of @TEXT's and CDATA's. The only XML-in...

(C++) While reading a file (ifstream), is there any way to direct it to make a new line?

While reading a file (ifstream), is there any way to direct it to make a new line? For instance, I would like for THIS to happen: myfile>>array[1]>>array[2]>>endl; Obviously, the "endl" just isn't allowed. Is there another way to do this? Edit---thanks for the quick responses guys! From a text file, I'm trying to store two strings...

C# compilation question: newlines in 1 statement causing error.

A simple question Consider this piece of code in C# String a; String b; String c; 1. a = 2. b = 3. //Comment 4. c = "a String"; During compilation, it was fine, but i hit an error when I run my application. From my logs, the error occur at the above. Question: Is the error caused by the comment in line 3? The error is "Ob...

Do line endings differ between Windows and Linux?

Hi all, I am trying to parse the linux /etc/passwd file in java. I'm currently reading each line through the scanner class in java and then using string.split() to delimit each line. The problem is that the line "list:x:38:38:Mailing List Manager:/var/list:/bin/sh" is treated by the scanner as 3 different lines: 1) "list:x:38:38:Maili...

New line in GridView cell

I'm binding a GridView to an LINQ query. Some of the fields in the objects created by the LINQ statement are strings, and need to contain new lines. Apparently, GridView HTML-encodes everything in each cell, so I can't insert a <br /> to create a new line within a cell. How do I tell GridView not to HTML encode the contents of cells? ...