Questions tagged [whitespace]

Whitespace, or white space, is often used to refer to any combination of spaces, tabs, and new lines which create blank space between text, either horizontally or vertically.

Whitespace, or white space, is often used to refer to any combination of spaces, tabs, and new lines which create blank (or white, originally referring to the background color behind it) space between text, either horizontally or vertically. White space is not represented by a visual character or symbol, but in most cases does occupy space on the page.

Whitespace Characters

The following characters are all defined as being whitespace.

  • U+0009 - Horizontal Tab
  • U+000A - Line Feed
  • U+000B - Vertical Tab
  • U+000C - Form Feed
  • U+000D - Carriage Return
  • U+0020 - Space
  • U+0085 - Next Line
  • U+00A0 - Non-Breaking Space
  • U+1680 - Ogham Space Mark
  • U+180E - Mongolian Vowel Separator
  • U+2000 - EN Quad
  • U+2001 - EM Quad
  • U+2002 - EN Space
  • U+2003 - EM Space
  • U+2004 - Three-per-EM Space
  • U+2005 - Four-per-EM Space
  • U+2006 - Six-per-EM Space
  • U+2007 - Figure Space
  • U+2008 - Punctuation Space
  • U+2009 - Thin Space
  • U+200A - Hair Space
  • U+2028 - Line Separator
  • U+2029 - Paragraph Separator
  • U+202F - Narrow Non-Breaking Space
  • U+205F - Medium Mathematical Space
  • U+3000 - Ideographic Space
4336 questions
150
votes
9 answers

How to remove duplicate white spaces in string using Java?

How to remove duplicate white spaces (including tabs, newlines, spaces, etc...) in a string using Java?
brainless
  • 5,698
  • 16
  • 59
  • 82
140
votes
12 answers

How to remove trailing whitespaces with sed?

I have a simple shell script that removes trailing whitespace from a file. Is there any way to make this script more compact (without creating a temporary file)? sed 's/[ \t]*$//' $1 > $1__.tmp cat $1__.tmp > $1 rm $1__.tmp
Viktor
  • 6,739
  • 7
  • 26
  • 29
140
votes
15 answers

How to remove trailing whitespace of all files recursively?

How can you remove all of the trailing whitespace of an entire project? Starting at a root directory, and removing the trailing whitespace from all files in all folders. Also, I want to to be able to modify the file directly, and not just print…
iamjwc
  • 1,456
  • 2
  • 10
  • 7
137
votes
7 answers

How to ignore whitespace in a regular expression subject string?

Is there a simple way to ignore the white space in a target string when searching for matches using a regular expression pattern? For example, if my search is for "cats", I would want "c ats" or "ca ts" to match. I can't strip out the whitespace…
Steven
  • 1,949
  • 2
  • 17
  • 30
135
votes
10 answers

Can you make valid Makefiles without tab characters?

target: dependencies command1 command2 On my system (Mac OS X), make seems to require that that Makefiles have a tab character preceding the the content of each command line, or it throws a syntax error. This is an annoyance when creating…
xyz
  • 27,223
  • 29
  • 105
  • 125
133
votes
20 answers

How can I escape white space in a bash loop list?

I have a bash shell script that loops through all child directories (but not files) of a certain directory. The problem is that some of the directory names contain spaces. Here are the contents of my test directory: $ls -F test Baltimore/ Cherry…
MCS
  • 22,113
  • 20
  • 62
  • 76
133
votes
14 answers

How to remove all white spaces in java

I have a programming assignment and part of it requires me to make code that reads a line from the user and removes all the white space within that line. the line can consist of one word or more. What I was trying to do with this program is…
Aiman Kh
  • 1,341
  • 2
  • 8
  • 4
130
votes
5 answers

How can I strip the whitespace from Pandas DataFrame headers?

I am parsing data from an Excel file that has extra white space in some of the column headings. When I check the columns of the resulting dataframe, with df.columns, I see: Index(['Year', 'Month ', 'Value']) ^ # …
Spike Williams
  • 35,795
  • 13
  • 48
  • 60
130
votes
5 answers

What does "1 line adds whitespace errors" mean when applying a patch?

I'm editing some markdown files of a cloned remote repository, and wanted to test creating and applying patches from one branch to another. However, every time I make any change at all, I get the following message during git apply: 0001-b.patch:16:…
Yarin
  • 173,523
  • 149
  • 402
  • 512
129
votes
4 answers

Atom text editor remove trailing whitespace on save

I use Sublime text. Now I am trying Atom. When I save any file in sublime text it does not include any trailing blank line. But saving any file in Atom leaves a trailing blank line. How do I force Atom not to leave trailing white spaces?
123
votes
11 answers

Whitespace Matching Regex - Java

The Java API for regular expressions states that \s will match whitespace. So the regex \\s\\s should match two spaces. Pattern whitespace = Pattern.compile("\\s\\s"); matcher = whitespace.matcher(modLine); while (matcher.find())…
user372743
122
votes
4 answers

Display element as preformatted text via CSS

Is there any way to emulate the display of a pre element via CSS? For example, can I keep the whitespace intact in this div by using a CSS rule?
Please procure the following items: - Soup - Jam - Hyphens …
Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
119
votes
11 answers

How to check if a char is equal to an empty space?

Here's what I've got: private static int countNumChars(String s) { for(char c : s.toCharArray()){ if (Equals(c," ")) } } But that code says it cannot find Symbol for that method. I remember Java having a comparer like this... Any…
delete
119
votes
10 answers

Strip whitespace from jsp output

How can I strip out extra whitespace from jsp pages' output? Is there a switch I can flip on my web.xml? Is there a Tomcat specific setting?
Seth Weiner
  • 2,999
  • 5
  • 26
  • 14
118
votes
11 answers

Replace whitespaces with tabs in linux

How do I replace whitespaces with tabs in linux in a given text file?
biznez
  • 3,911
  • 11
  • 33
  • 37