Stripping off extra spaces from a string

CJam, 7 bytes

q~S%S*p

Code Explanation

CJam has reserved all capital letters as inbuilt variables. So S has a value of a space here.

q~          e# Read the input (using q) and evaluate (~) to get the string
  S%        e# Split on running lengths (%) of space
    S*      e# Join (*) the splitted parts by single space
      p     e# Print the stringified form (p) of the string.

This removes the trailing and leading spaces as well

Try it online here


///: 18 characters

/  / //" /"// "/"/

Sample run:

(Using faubiguy's interpreter from his Perl answer for Interpret /// (pronounced 'slashes').)

bash-4.3$ ( echo -n '/  / //" /"// "/"/'; echo '"   foo  *  bar   "'; ) | slashes.pl
"foo * bar"

Perl, 22

(20 bytes of code, plus 2 command line switches)

s/ +/ /g;s/" | "/"/g

Needs to be run with the -np switch so that $_ is automatically filled via stdin and printed to stdout. I'm going to assume this adds 2 to the byte count.