newline

Properly detect line-endings of a file in Perl?

跟風遠走 提交于 2019-12-23 09:56:25
问题 Problem: I have data (mostly in CSV format) produced on both Windows and *nix, and processed mostly on *nix. Windows uses CRLF for line endings and Unix uses LF. For any particular file I don't know whether it has windows or *nix line endings. Up until now, I've been writing something like this to handle the difference: while (<$fh>){ tr/\r\n//d; my @fields = split /,/, $_; # ... } On *nix the \n part is equivalent to chomping, and additionally gets rid of \r (CR) if it's a windows-produced

Properly detect line-endings of a file in Perl?

北城以北 提交于 2019-12-23 09:56:12
问题 Problem: I have data (mostly in CSV format) produced on both Windows and *nix, and processed mostly on *nix. Windows uses CRLF for line endings and Unix uses LF. For any particular file I don't know whether it has windows or *nix line endings. Up until now, I've been writing something like this to handle the difference: while (<$fh>){ tr/\r\n//d; my @fields = split /,/, $_; # ... } On *nix the \n part is equivalent to chomping, and additionally gets rid of \r (CR) if it's a windows-produced

Printf without newline in assembly

戏子无情 提交于 2019-12-23 09:39:08
问题 I've recently read this article on using printf and scanf in assembly: Meaning of intfmt: db "%d", 10, 0 in assembly In particular it says "In printf, the newline prints a newline and then (if the output is in line buffered mode, which it probably is), flushes the internal output buffer so you can actually see the result. So when you remove the 10, there's no flush and you don't see the output." However I do not know what to do if I do not want a newline after my output in my assembly file.

Replace newlines, but keep the blank lines

旧街凉风 提交于 2019-12-23 09:32:04
问题 I want to replace newlines (\r\n) with space, but I want to keep the blank lines. In other words, I want to replace \r\n with ' ', if \r\n is not preceded by another \r\n. For example: line 1 line 2 line 3 line 4 Shold end up as... line 1 line 2 line 3 line 4 But not as "line 1 line 2 line 3 line 4", which is what I'm doing right now with this preg_replace("/\r\n/", " ", $string); 回答1: Try this: (?<!\n)\n(?!\n) Of course, you can change \n to whatever you need. Working example: http://ideone

What is the difference between '\n' or “\n” in C++?

二次信任 提交于 2019-12-23 07:27:08
问题 I've seen the new line \n used 2 different ways in a few code examples I've been looking at. The first one being '\n' and the second being "\n" . What is the difference and why would you use the '\n' ? I understand the '\n' represents a char and "\n" represents a string but does this matter? 回答1: '\n' is a character constant. "\n" is a pointer to character array equivalent to {'\n', '\0'} ( \n plus the null terminator) EDIT I realize i explained the difference, but didn't answer the question.

What is the difference between '\n' or “\n” in C++?

有些话、适合烂在心里 提交于 2019-12-23 07:27:01
问题 I've seen the new line \n used 2 different ways in a few code examples I've been looking at. The first one being '\n' and the second being "\n" . What is the difference and why would you use the '\n' ? I understand the '\n' represents a char and "\n" represents a string but does this matter? 回答1: '\n' is a character constant. "\n" is a pointer to character array equivalent to {'\n', '\0'} ( \n plus the null terminator) EDIT I realize i explained the difference, but didn't answer the question.

HTML textarea ignores 1st new line character, why?

▼魔方 西西 提交于 2019-12-23 07:23:03
问题 Could you explain why this: <script type="text/javascript"> document.write("<textarea cols='10' rows='10'>" + "\nhello\nbabe\n" + "</textarea>"); </script> renders a textarea with one new line at the bottom, but NO new line at the top ? Tested IE8, FF11, Safari 5.1, Chrome 24 And it's not a JS issue, even when you write HTML in page you get the same result, i.e. <textarea cols='10' rows='10'> hello babe </textarea> The 1st new line is still missing!!! I need to add another new line at the top

Having problems using myString.split(“\n”);

天涯浪子 提交于 2019-12-23 07:03:15
问题 I need to split an input string into many parts. The splits should occur at "\n" (literally backslash-n, not the newline character). E.g., I want to turn this: x = [2,0,5,5]\ny = [0,2,4,4]\ndraw y #0000ff\ny = y & x\ndraw y #ff0000 into this: x = [2,0,5,5] y = [0,2,4,4] draw y #0000ff y = y & x draw y #ff0000 I would have thought that stringArray = string.split("\n"); would have been sufficient. But it gives me the same output as input in the following code: public static void main(String[]

Having problems using myString.split(“\n”);

丶灬走出姿态 提交于 2019-12-23 07:02:17
问题 I need to split an input string into many parts. The splits should occur at "\n" (literally backslash-n, not the newline character). E.g., I want to turn this: x = [2,0,5,5]\ny = [0,2,4,4]\ndraw y #0000ff\ny = y & x\ndraw y #ff0000 into this: x = [2,0,5,5] y = [0,2,4,4] draw y #0000ff y = y & x draw y #ff0000 I would have thought that stringArray = string.split("\n"); would have been sufficient. But it gives me the same output as input in the following code: public static void main(String[]

fgets() Not Ignoring New Line

旧巷老猫 提交于 2019-12-23 06:28:28
问题 For my practice assignment I have to use either gets() or fgets(). I chose fgets() as its more secure. The first input is meant to be able to hold a maximum of 5 characters. So i gave the char array a size of 6 to accommodate the trailing '\0'. I found the fgets() issue of it adding a trailing '\n' when you press Enter (using stdin with fgets()) I done a bit of research and found a for loop to try and get rid of it. However, it doesnt seem to be working and i cant for the life of me figure