newline

How to remove “\n” in a list of lists (python)

北慕城南 提交于 2019-12-11 13:20:08
问题 I have a giant list of lists that I imported from a file like this: letters = [] for i in range(len(string)): let = [] for j in range(7): line = infile.readline() let = let + [line] letters.append(let) infile.readline() Its a big list of lists, but each secondary list has a \n at the end of it. [[' ### \n', ' ## ## \n', ' ## ## \n', '## ##\n', '#########\n', '## ##\n', '## ##\n'], ['######## \n', '## ##\n', '## ##\n', '######## \n', '## ##\n', '## ##\n', '######## \n'], ... ]] How do I remove

Mixing javascript, jQuery and PHP, newline

霸气de小男生 提交于 2019-12-11 12:58:14
问题 Ok, so I have a few things here: Javascript: desc = "line 1 \n line 2" jQuery: $("#msg").text(desc); PHP: const NUM = 555; What I want, is to change the text of the <p> with the id of msg , so that it would contain a piece of text with a number of lines, and in one of them the number from the PHP constant. Like so: Line 1 Line 2 555, Line 2 continued Line 3 My problem is how do I mix them all? I tried the following: var desc = "line 1 \n line2" + <?php echo NUM ?> +"\n line 3"; and that doesn

Python: How to write a list of strings on separate lines but without a blank line

梦想与她 提交于 2019-12-11 12:09:32
问题 EDIT: See bottom of post for the entire code I am new to this forum and I have an issue that I would be grateful for any help solving. Situation and goal: - I have a list of strings. Each string is one word, like this: ['WORD', 'LINKS', 'QUOTE' ...] and so on. - I would like to write this list of words (strings) on separate lines in a new text file. - One would think the way to do this would be by appending the '\n' to every item in the list, but when I do that, I get a blank line between

Android Studio: Error in Layout Files - Header expected

≡放荡痞女 提交于 2019-12-11 10:58:19
问题 Every time I create a TextView and set a text to it, the AS-Editor would throw an error: "Header expected - Manifest file doesn't end with a final newline" The code: <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> AndroidManifest.xml: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="eu.myurl.myproject" android:versionCode="1" android:versionName="1.0" >

Strip new line characters within a quoted string in unix

落爺英雄遲暮 提交于 2019-12-11 09:27:57
问题 I have a text file that goes like this: abc 123 xyz "abc 123" xyz I want to replace new lines with a space (' ') if the new line occurs within a quoted string. So I want output: abc 123 xyz abc 123 xyz Is there a way to write a program in Unix for this? 回答1: You can print a new line or just a space depending on how many " how got so far. This way, new line will just be printed if we are closing quotes. $ awk '{n=split($0,a,"\""); val+=(n-1); gsub("\"",""); printf "%s%s", $0, (val%2?" ":"\n")}

jQuery dataTables : Export with newline / break in cell, using jQuery

不打扰是莪最后的温柔 提交于 2019-12-11 08:32:30
问题 I´m trying to generate an exportable datatable with the plugin "jquery.dataTable". But for design reasons I need linebreaks inside the cells. For the HTML view I simply use <br> , but if I try to export this f.e into a PDF, it will cause to break the output from the first occurring br, so I googled around and tried to pre-process the data and replace breaks with newline characters but this will cause the PDF export to break at the first br for even a lot of rows. I have no idea. Here's the

use sed to in-place replace a line in a file with multiple lines from stdin or HEREDOCs

与世无争的帅哥 提交于 2019-12-11 08:02:31
问题 I want to replace a line in a file with multiple lines. I know I can use \n in the sed replace, but that is rather ugly. I was hoping to HEARDOCs. So I can do this to replace the line with multiple lines: $ cat sedtest DINGO=bingo $ sed -i -e "s/^DINGO.*$/# added by $(whoami) on $(date)\nDINGO=howdy/" sedtest $ cat sedtest # added by user on Sun Feb 3 08:55:44 EST 2019 DINGO=howdy In the command I want to put the replacement in new lines so it's easier to read/understand. So far I have been

substr_count not working with new lines?

[亡魂溺海] 提交于 2019-12-11 07:55:19
问题 This is driving me nuts, it keeps returning 0 substr_count('df d fd f df', '\n'); if I use a letter like "d", it works fine substr_count('df d fd f df', 'd'); Can anyone shed some light on this? Thanks 回答1: You need to use double quotes for control characters: var_dump(substr_count('df d fd f df', "\n")); 回答2: '\n' is not the same as "\n". '\n' is text comprising a slash and the letter "n", whereas "\n" is a newline character. Suggest you read the relevant section of the PHP manual about

Perl match newline in `-0` mode

萝らか妹 提交于 2019-12-11 07:48:29
问题 Question Suppose I have a file like this: I've got a loverly bunch of coconut trees. Newlines! Bahahaha Newlines! the end. I'd like to replace an occurence of "Newlines!" that is surrounded by blank lines with (say) NEWLINES!. So, ideal output is: I've got a loverly bunch of coconut trees. NEWLINES! Bahahaha Newlines! the end. Attempts Ignoring "surrounded by newlines", I can do: perl -p -e 's@Newlines!@NEWLINES!@g' input.txt Which replaces all occurences of "Newlines!" with "NEWLINES!". Now

How to recognize special eol character when I see it, using Python?

烂漫一生 提交于 2019-12-11 06:55:51
问题 I'm scraping a set of originally pdf files, using Python. Having gotten them to text, I had a lot of trouble getting the line endings out. I couldn't figure out what the line separator was. The trouble is, I still don't know. It's not a '\n' , or, I don't think, '\r\n' . However, I've managed to isolate one of these special characters. I literally have it in memory, and by doing a call to my_str.replace(eol, '') , I can remove all of these characters from one of my files. So my question is