Questions tagged [spaces]

The space character, `U+0020`, used to separate words/tokens in most natural and programming languages.

The space character, U+0020, used to separate words/tokens in most natural and programming languages. Space is a whitespace character.

Spaces are frequently of concern to programmers in the context of languages with significant whitespace (e.g. Python), source code indentation, and separating tokens. Separating tokens correctly is important for shell scripts, URIs, file names/paths, text processing, and string formatting. Questions regarding all of these areas are common on Stack Overflow, as spaces appearing unexpectedly can cause unexpected behavior whose source is not immediately obvious.

"Spaces" may also refer to the virtual desktop functionality of Mac OS X, first referred to as "Spaces" in OS X 10.5.

1024 questions
34
votes
5 answers

Removing spaces from a variable input using PowerShell 4.0

I've tried a few things already but they don't seem to work for some reason. Basically what I'm attempting to do is have a user input a value using the "Read-host" cmdlet, then strip it of any spaces. I tried: $answer = read-host $answer.replace('…
cloudnyn3
  • 769
  • 4
  • 10
  • 15
33
votes
6 answers

Read input numbers separated by spaces

This may be a total beginner's question, but I have yet to find an answer that works for me. Currently, I'm writing a program for a class that takes in a user's input (which can be one or more numbers separated by spaces), then determines whether…
Raymond Aaron
  • 333
  • 1
  • 3
  • 6
33
votes
13 answers

using fstream to read every character including spaces and newline

I wanted to use fstream to read a txt file. I am using inFile >> characterToConvert, but the problem is that this omits any spaces and newline. I am writing an encryption program so I need to include the spaces and newlines. What would be the proper…
Tomek
30
votes
7 answers

Adding whitespace in Java

There is a class trim() to remove white spaces, how about adding/padding? Note: " " is not the solution.
Sobiaholic
  • 2,927
  • 9
  • 37
  • 54
27
votes
13 answers

Alternatives to " " for creating strings containing multiple whitespace characters

I'm wondering if there's a more OO way of creating spaces in C#. Literally Space Code! I currently have tabs += new String(" "); and I can't help but feel that this is somewhat reminiscent of using "" instead of String.Empty. What can I use to…
Jamie Dixon
  • 53,019
  • 19
  • 125
  • 162
22
votes
3 answers

Elastic Search wildcard search with spaces

I have the following query. I'm trying to find values of 'hello world', but it returns zero results. However, when value = 'hello*', it does give me that expected result. Any idea how I can change my query to give me that hello world result? I've…
user1530318
  • 25,507
  • 15
  • 37
  • 48
22
votes
8 answers

simplest way to check for just spaces in ruby

So I know in ruby that x.nil? will test if x is null. What is the simplest way to test if x equals ' ', or ' '(two spaces), or ' '(three spaces), etc? Basically, I'm wondering what the best way to test if a variable is all whitespace?
user301752
  • 275
  • 1
  • 2
  • 7
22
votes
9 answers

How do I replace tabs with spaces within variables in PHP?

$data contains tabs, leading spaces and multiple spaces. I wish to replace all tabs with a space. Multiple spaces with one single space, and remove leading spaces. In fact somthing that would turn this input data: [ asdf asdf asdf …
Arthur
  • 3,376
  • 11
  • 43
  • 70
22
votes
7 answers

Java String trim has no effect

Java String trim is not removing a whitespace character for me. String rank = (some method); System.out.println("(" + rank + ")"); The output is (1 ). Notice the space to the right of the 1. I have to remove the trailing space from the string…
Terry Li
  • 16,870
  • 30
  • 89
  • 134
22
votes
3 answers

Why does the cmd.exe shell on Windows fail with paths using a forward-slash ('/'') path separator?

Just when I'd thought I'd seen it all with Windows path issues, I've now encountered a case that only fails when '/' (forward-slash) is used as the path separator is used: C:\temp\tcbugs>mkdir "dir1 with spaces" C:\temp\tcbugs>echo hi > "dir1 with…
Garen
  • 941
  • 2
  • 9
  • 20
20
votes
3 answers

Spaces between html attributes and values?

Are they allowed? and do they work with all browsers? Example:
Ian Storm Taylor
  • 8,520
  • 12
  • 55
  • 72
19
votes
2 answers

How can I programmatically add a space to mission control?

I want to create a new space (and also be able to delete it later), without having to go through the standard misson control gui. Is there any way to do this programmatically? Either via terminal commands, applescript or some cocoa?
Dag Stuan
  • 191
  • 1
  • 4
19
votes
2 answers

Notepad++ Tab Settings

See Convert tabs to spaces in Notepad++ I have started on a personal quest to learn python and after following a Google lecture online the instructor advocated changing your tabs to spaces. I have browsed around in notepad++ and gone to the…
ssirovi
  • 259
  • 1
  • 2
  • 5
19
votes
3 answers

What the meaning of various types of white space in Java?

What is difference of below escape sequences for white space? \t, \n, \x0B, \f and \r.
Praveen
  • 90,477
  • 74
  • 177
  • 219
19
votes
7 answers

How to display tabs as 4 spaces in gnome-terminal

Actually gnome-terminal display tabs as 8 spaces, and this is very annoying when you cat files or view diffs, is there some way to change this permanently?
Htechno
  • 5,901
  • 4
  • 27
  • 37
1 2
3
68 69