removing-whitespace

Regex: How to remove extra spaces between strings in Perl

↘锁芯ラ 提交于 2019-12-19 18:25:25
问题 I am working on a program that take user input for two file names. Unfortunately, the program can easily break if the user does not follow the specified format of the input. I want to write code that improves its resiliency against these types of errors. You'll understand when you see my code: # Ask the user for the filename of the qseq file and barcode.txt file print "Please enter the name of the qseq file and the barcode file separated by a comma:"; # user should enter filenames like this:

newline and dash not working correctly in jinja

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 07:53:43
问题 How could I generate the expected output ? Thanks jinja template {%- for field in fields -%} - name: {{field}} type: string {%- endfor -%} output - name: operating revenue type: string- name: gross operating profit type: string- expected output - name: operating revenue type: string - name: gross operating profit type: string code from jinja2 import Template fields = ["operating revenue", "gross operating profit", "EBITDA", "operating profit after depreciation", "EBIT", "date"] template_file

How do I remove spaces in all attribute values using xslt?

女生的网名这么多〃 提交于 2019-12-19 04:09:52
问题 I want to remove spaces from all attributes in my xmls using xslt. I used strip-space , but that removes the spaces from nodes. My input xml is: <OrderList> <Order OrderDate="26-July" OrderNo="ORDER 12345" CustomertName="JOHN DOE" OrderKey="ORDKEY12345"> <ShipAddress AddressLine="ABC Colony" FirstName="John" LastName="Doe "/> </Order> </OrderList> and the xsl I used to get rid of the spaces in the attributes like CustomertName="JOHN DOE" is: <?xml version="1.0" encoding="UTF-8"?> <xsl

remove whitespace in std::string [duplicate]

我们两清 提交于 2019-12-18 12:54:10
问题 This question already has answers here : Remove spaces from std::string in C++ (14 answers) Closed 4 years ago . In C++, what's an easy way to turn: This std::string \t\tHELLO WORLD\r\nHELLO\t\nWORLD \t Into: HELLOWORLDHELLOWORLD 回答1: Simple combination of std::remove_if and std::string::erase. Not totally safe version s.erase( std::remove_if( s.begin(), s.end(), ::isspace ), s.end() ); For safer version replace ::isspace with std::bind( std::isspace<char>, _1, std::locale::classic() )

How do I split a string by whitespace and ignoring leading and trailing whitespace into an array of words using a regular expression?

对着背影说爱祢 提交于 2019-12-17 15:53:11
问题 I typically use the following code in JavaScript to split a string by whitespace. "The quick brown fox jumps over the lazy dog.".split(/\s+/); // ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog."] This of course works even when there are multiple whitespace characters between words. "The quick brown fox jumps over the lazy dog.".split(/\s+/); // ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog."] The problem is when I have a string that has leading

git remove trailing whitespace in new files before commit

心不动则不痛 提交于 2019-12-17 15:47:08
问题 I know removing trailing whitespace can be done with a pre-commit hook. I am interested in doing it manually. I read the question here: Make git automatically remove trailing whitespace before committing - Stack Overflow The answer closest to what I want is the "automatic version" from ntc2: (export VISUAL=: && git -c apply.whitespace=fix add -ue .) && git checkout . && git reset That command works well except it seems to be only for changes on files that are already in the repo, not new

Mysterious whitespace in between Bootstrap2 Navbar and row underneath

雨燕双飞 提交于 2019-12-17 09:45:52
问题 I am using Bootstrap's Navbar and Bootsrap's grid to display a Navbar with a image immediately underneath the Navbar. However, for some reason there is whitespace between this Navbar and the image. When I use firebug to investigate the location of the whitespace, it looks like the Navbar is top-aligned within its containing . I have tried to fix this by using CSS to bottom-align the navbar, to no avail. How can I eliminate this whitespace? <!-- Top Navigation Bar --> <div class="row" id=

Replace space with an underscore

邮差的信 提交于 2019-12-14 03:45:01
问题 I am trying to write something that will replace all the spaces in a string with an underscore. What I have so far. string space2underscore(string text) { for(int i = 0; i < text.length(); i++) { if(text[i] == ' ') text[i] = '_'; } return text; } For the most part this would work, if I was doing something like. string word = "hello stackoverflow"; word = space2underscore(word); cout << word; That would output "hello_stackoverflow", which is just what I want. However if I was to do something

remove whitespaces tail from string (char*)

随声附和 提交于 2019-12-13 02:56:40
问题 hello I've got text file with lines format 1|few ewf ew fewfew I need to parse it but I don't know how can I drop whitespaces tail from second value I don't know. Here is my segmentation fault try so far char* token1; char* token2; char* search = "|"; char* search2 = " "; // double space because string can contains single space while (fgets(line, 150, f)) { token1 = strtok(line, search); token2 = strtok(search, search2); // <- segfault //token2 = strtok(NULL, search); <- contains a lot of

Remove Space at end of String but keep new line symbol

心不动则不痛 提交于 2019-12-12 16:26:13
问题 How can I check if a Python string at any point has a single space before new line ? And if it does, I have to remove that single space, but keep the new line symbol. Is this possible? 回答1: def remspace(my_str): if len(my_str) < 2: # returns ' ' unchanged return my_str if my_str[-1] == '\n': if my_str[-2] == ' ': return my_str[:-2] + '\n' if my_str[-1] == ' ': return my_str[:-1] return my_str Results: >>> remspace('a b c') 'a b c' >>> remspace('a b c ') 'a b c' >>> remspace('a b c\n') 'a b c