Questions tagged [removing-whitespace]

For issues related to removing additional blank-characters like spaces, tabs and new lines or issues related to removing unwanted whitespace.

Related tags:

756 questions
1198
votes
15 answers

Remove all whitespace in a string

I want to eliminate all the whitespace from a string, on both ends, and in between words. I have this Python code: def my_handle(self): sentence = ' hello apple ' sentence.strip() But that only eliminates the whitespace on both sides of…
not 0x12
  • 19,360
  • 22
  • 67
  • 133
493
votes
19 answers

Efficient way to remove ALL whitespace from String?

I'm calling a REST API and am receiving an XML response back. It returns a list of a workspace names, and I'm writing a quick IsExistingWorkspace() method. Since all workspaces consist of contiguous characters with no whitespace, I'm assuming the…
Corey Ogburn
  • 24,072
  • 31
  • 113
  • 188
479
votes
3 answers

Substitute multiple whitespace with single whitespace in Python

I have this string: mystring = 'Here is some text I wrote ' How can I substitute the double, triple (...) whitespace chracters with a single space, so that I get: mystring = 'Here is some text I wrote'
creativz
  • 10,369
  • 13
  • 38
  • 35
414
votes
15 answers

How can I trim leading and trailing white space?

I am having some trouble with leading and trailing white space in a data.frame. For example, I look at a specific row in a data.frame based on a certain condition: > myDummy[myDummy$country == c("Austria"),c(1,2,3:7,19)] [1] codeHelper …
mropa
  • 11,562
  • 10
  • 33
  • 29
298
votes
9 answers

Remove white space below image

In Firefox only my video thumbnails are displaying mysterious 2-3 pixels of white space between the bottom of my image and its border (see below). I've tried everything I can think of in Firebug with no luck. How can I remove this white space?
Ryan
  • 6,027
  • 16
  • 52
  • 89
257
votes
7 answers

How to remove all white space from the beginning or end of a string?

How can I remove all white space from the beginning and end of a string? Like so: "hello" returns "hello" "hello " returns "hello" " hello " returns "hello" " hello world " returns "hello world"
pedram
  • 3,647
  • 6
  • 24
  • 28
222
votes
14 answers

How can you automatically remove trailing whitespace in vim

I am getting 'trailing whitespace' errors trying to commit some files in Git. I want to remove these trailing whitespace characters automatically right before I save Python files. Can you configure Vim to do this? If so, how?
Paul D. Eden
  • 19,939
  • 18
  • 59
  • 63
209
votes
7 answers

How to remove leading and trailing white spaces from a given html string?

I've the following HTML string. What would be sample code in JavaScript to remove leading and trailing white spaces from this string?

  

 
Trimming using JavaScript



all leading and trailing…
Sunil
  • 20,653
  • 28
  • 112
  • 197
159
votes
10 answers

How to remove leading and trailing whitespace in a MySQL field?

I have a table with two fields (countries and ISO codes): Table1 field1 - e.g. 'Afghanistan' (without quotes) field2 - e.g. 'AF'(without quotes) In some rows the second field has whitespace at the start and/or end, which is affecting…
KB.
  • 3,549
  • 4
  • 23
  • 29
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?
106
votes
3 answers

Extra space under textarea, differs along browsers

There`s some extra space under textarea tag. From 1 to 4 pixels in different browsers. The markup is very simple: …
Roman
  • 1,946
  • 3
  • 20
  • 28
80
votes
6 answers

Strip whitespace from strings in a column

I am using python csvkit to compare 2 files like this: df1 = pd.read_csv('input1.csv', sep=',\s+', delimiter=',', encoding="utf-8") df2 = pd.read_csv('input2.csv', sep=',\s,', delimiter=',', encoding="utf-8") df3 = pd.merge(df1,df2,…
fightstarr20
  • 11,682
  • 40
  • 154
  • 278
79
votes
4 answers

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

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…
natlee75
  • 5,097
  • 3
  • 34
  • 39
70
votes
1 answer

Optional Whitespace Regex

I'm having a problem trying to ignore whitespace in-between certain characters. I've been Googling around for a few days and can't seem to find the right solution. Here's my code: // Get Image data preg_match('#
jameslfc19
  • 1,084
  • 1
  • 10
  • 14
68
votes
7 answers

How to remove trailing whitespaces for multiple files?

Are there any tools / UNIX single liners which would remove trailing whitespaces for multiple files in-place. E.g. one that could be used in the conjunction with find.
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
1
2 3
50 51