tags:

views:

193

answers:

9

Can someone give me a real-world scenario of a method/function with a string argument which came from user input (e.g. form field, parsed data from file, etc.) where leading or trailing spaces SHOULD NOT have been trimmed?

I can't ever recall such a situation for myself.

EDIT: Mind you, I didn't say trimming any whitespace. I said trimming leading or trailing (only) spaces (or whitespace).

+10  A: 

Search string in any "Find" dialog in an editor.

Pavel Minaev
A: 

A paragraph entry.

Spencer Ruport
+1  A: 

If you are inputting code. There may be a scenario where whitespace at the begining and end are necessary.

Also, look at Stack Overflow's markdown editor. Code examples are indented. If you posted just a code example, then it will require leading and trailing white space not be trimmed.

alex
+8  A: 

Password input boxes. There's lots of data out there, where whitespace can genuinely be considered important part of the string. It narrows things down alot by making it starting and ending whitespace only, but there's still many examples. Stuff you pass through a PHP style nl2br function.

Svend
+2  A: 

Perhaps a Whitespace interpreter.

Mark Rushakoff
Real world? ;).....
Daniel Straight
A: 

If the input is python code (say, for a pastebin kinda thing), you certainly can't trim leading white space; but you also can't trim trailing white space, because it could be a part of a multi-line string (triple quoted string).

hasen j
+1  A: 

A Stackoverflow answer, or more generally input written in markdown (four leading spaces -> code block).

sth
A: 

I've used whitespace as a delimiter before, so there. Also, for anything that involves concatenating multiple inputs, removing leading/trailing whitespace can break formatting or possibly do worse. Aside from that, as Spencer said, for indented paragraphs you probably would not want to remove the leading whitespace.

Coding With Style
+1  A: 

Python....