digitalmars.D.learn - Compress spaces to one space
- Andrej Mitrovic (3/3) Feb 21 2012 Is there a Phobos function to compress all spaces to just one space in a...
- bearophile (7/11) Feb 21 2012 import std.string;
- Andrej Mitrovic (2/14) Feb 21 2012
- Andrej Mitrovic (5/15) Feb 21 2012 Yikes! I didn't even notice it squeezes *all* duplicates. You see in
Is there a Phobos function to compress all spaces to just one space in a string? E.g. " foo bar " becomes: " foo bar "
Feb 21 2012
Andrej Mitrovic:Is there a Phobos function to compress all spaces to just one space in a string? E.g. " foo bar " becomes: " foo bar "import std.string; void main() { assert(" foo bar ".squeeze() == " fo bar "); } Bye, bearophile
Feb 21 2012
Oh cool, it even takes an optional parameter. Thanks! On 2/21/12, bearophile <bearophileHUGS lycos.com> wrote:Andrej Mitrovic:Is there a Phobos function to compress all spaces to just one space in a string? E.g. " foo bar " becomes: " foo bar "import std.string; void main() { assert(" foo bar ".squeeze() == " fo bar "); } Bye, bearophile
Feb 21 2012
On 2/21/12, bearophile <bearophileHUGS lycos.com> wrote:Andrej Mitrovic:Yikes! I didn't even notice it squeezes *all* duplicates. You see in my original code I just wanted extra spaces removed, not the chars themselves. So the right call is: squeeze(" ")Is there a Phobos function to compress all spaces to just one space in a string? E.g. " foo bar " becomes: " foo bar "import std.string; void main() { assert(" foo bar ".squeeze() == " fo bar "); }
Feb 21 2012