replacement for squeeze and removechars.

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 18 08:41:44 PDT 2017


On Tuesday, 18 July 2017 at 15:28:06 UTC, Antonio Corbi wrote:
> Hi all,
>
> I'm trying dmd-2.075.0-rc1 in one of my projects where I use 
> `squeeze` and `removechars`. Both of them are flagged as 
> obsolete and in the docs we are suggested to use functions from 
> std.regex and/or std.algorithm.
>
> Does any one kow a one-liner from std.regex or std.algorithm 
> that can take the role of those deprecated functions?
>
> Thank's
> A. Corbi

As Seb somewhat undiplomatically put, there are replacements 
listed in the changelog.

Use std.regex.replaceAll to replace std.string.removechars:

import std.string;
import std.regex;

// old
"abc".removechars("a-z");

// new
"abc".replaceAll(regex("[a-z]"), "");



Use std.algorithm.iteration.uniq to replace std.string.squeeze:

import std.algorithm;
import std.string;

// old
"hello".squeeze;

// new
"hello".uniq;



Though it would be nice to have these alternatives listed right 
there in the deprecation message.


More information about the Digitalmars-d-learn mailing list