newline

Determine what line ending is used in a text file

百般思念 提交于 2019-12-21 04:04:36
问题 Whats the best way in C# to determine the line endings used in a text file (Unix, Windows, Mac)? 回答1: Notice that text files may have inconsistent line endings. Your program should not choke on that. Using ReadLine on a StreamReader (and similar methods) will take care of any possible line ending automatically. If you manually read lines from a file, make sure to accept any line endings, even if inconsistent. In practice, this is quite easy using the following algorithm: Scan ahead until you

Can you force Vim to show a blank line at the end of a file?

痴心易碎 提交于 2019-12-21 03:43:22
问题 When I open a text file in Notepad, it shows a blank line if there is a carriage return at the end of the last line containing text. However, in Vim it does not show this blank line. Another thing I've noticed is that the Vim editor adds a carriage return to the last line by default (even though it doesn't show it). I can tell, because if I open a file in Notepad that was created in Vim, it shows a blank line at the end of the file. Anyway, I can live with these two differences, but I'm

C# Regex - Remove extra whitespaces but keep new lines [duplicate]

廉价感情. 提交于 2019-12-21 01:20:49
问题 This question already has answers here : Match whitespace but not newlines (6 answers) Closed 5 years ago . I am using this regex : Regex.Replace(value.Trim(), @"\s+", " "); To trim and minimize extra spaces into one space. The problem is that it also removes new lines from the text. How can I fix the regex so that it will keep the new lines ? 回答1: Exclude CRLF's [^\S\r\n]+ within the whitespace class. [^] is a negative class. \S is a negative class which equals not [ space, tab, ff, lf, cr ]

Python: write a list with non-ASCII characters to a text file

牧云@^-^@ 提交于 2019-12-21 00:42:50
问题 I'm using python 3.4 and I'm trying to write a list of names to a text file. The list is as follows: my_list = ['Dejan Živković','Gregg Berhalter','James Stevens','Mike Windischmann', 'Gunnar Heiðar Þorvaldsson'] I use the following code to export the list: file = open("/Users/.../Desktop/Name_Python.txt", "w") file.writelines( "%s\n" % item for item in my_list ) file.close() But it does not work. Python seems not to like non-ASCII characters and gives me the following errors:

R - new line in paste() function [duplicate]

孤人 提交于 2019-12-20 18:25:11
问题 This question already has answers here : Printing newlines with print() in R (4 answers) Closed 5 years ago . How can we insert a new line when using the function paste() or any function that concatenates strings in R? There are many web pages on this topic but none answers clearly or gives a solution that works. I precise I don't want to use the function cat, I need to work with string of characters. Here are all my attempts (derived from all the suggestions on from different forum), they

Removing newline from a csv file

你说的曾经没有我的故事 提交于 2019-12-20 10:57:25
问题 I am trying to process a csv file in python that has ^M character in the middle of each row/line which is a newline. I cant open the file in any mode other than 'rU'. If I do open the file in the 'rU' mode, it reads in the newline and splits the file (creating a newline) and gives me twice the number of rows. I want to remove the newline altogether. How? 回答1: Note that, as the docs say: csvfile can be any object which supports the iterator protocol and returns a string each time its next()

git and CR vs LF (but NOT CRLF)

拜拜、爱过 提交于 2019-12-20 10:45:01
问题 This may sound like a redundant question (and may very well be a redundnant question) but I can't find the answer. Here's the situation: My application is creating text files that have CR's as line endings. More specifically I'm not explicitly setting the line endings to CR, it just happens to be the output of the command I'm using to get the text body. Of course I could manually convert the CR's to LF's but I don't want to if I can avoid it. Git's treating these files as a single line (e.g.

jinja2 how to remove trailing newline

时间秒杀一切 提交于 2019-12-20 09:48:16
问题 I'm using jinja 2 to output a yaml file but can't seem to get rid of a trailing newline and the end of a for loop. Eg the below - request: path: {{ path }} headers: origin: 'somedomain.com' user-agent: 'agent' referer: 'some.domain.com' authority: 'somedomain.com' querystring: {% for key, value in querystring.items() -%} {{ key }}: '{{ value }}' {% endfor %} response: content: file: {{ content }} gives me the output: - request: path: /some/path headers: origin: 'somedomain.com' user-agent:

Insert a newline without entering in insert mode, vim

匆匆过客 提交于 2019-12-20 09:33:26
问题 I want insert newlines in normal mode in vim using Shift-Enter and Ctrl-Enter . I try some solutions and mixing solutions from Vim Wikia - Insert newline without entering insert mode but Shift-Enter and Ctrl-Enter didn't respond: " put a new line before or after to this line nnoremap <S-CR> m`o<Esc>`` nnoremap <C-CR> m`O<Esc>`` " reverse J command nnoremap <C-J> vaW<Esc>Bi<CR><Esc>k:s/\s\+$//<CR>$ 回答1: My alternative is using oo (resp. OO ) to insert a new line under (resp. over) the current

Git core.safecrlf different behavior on files with same line endings

北慕城南 提交于 2019-12-20 08:45:34
问题 I have Windows machine with VS project and I use both Visual Studio and tools from Cygwin environment including Git. Sometimes I get different line endings in files after editing. I want simple solution to check files' line ending consistency before they go to the repo. Git's core.safecrlf is the right thing I suppose. Now I have a strange behavior: Files A and B with following parameters: $file A A: HTML document, UTF-8 Unicode text, with CRLF line terminators $file B B: HTML document, UTF-8