Checking if a string contains a string?
Ali Çehreli
acehreli at yahoo.com
Wed Oct 16 23:35:30 PDT 2013
On 10/16/2013 11:27 PM, Jeremy DeHaan wrote:
> Maybe I am just tired or something, but I tried searching for a way that
> is already included in phobos for checking if a string contains another
> string and couldn't find anything. I managed to write my own function
> for doing this, but I figured I would ask in case I am crazy and just
> missed a built in method for doing this.
There are several search functions in std.algorithm.
findSplit() is a versatile one, providing three ranges: before, at, and
after the searched string.
import std.algorithm;
void main()
{
auto s = "hello cool world";
auto result = s.findSplit("cool");
assert(result[0] == "hello ");
assert(result[1] == "cool");
assert(result[2] == " world");
}
Ali
More information about the Digitalmars-d-learn
mailing list