"strstr" D equivalent

Salih Dincer salihdb at hotmail.com
Fri Jul 29 13:44:47 UTC 2022


**Short version:**

```d
import std.string;
import std.stdio;

void find (string str, string substr) {
     if(auto pos = str.indexOf(substr)) {
         writefln("found the string '%s' in '%s' at position: %s", 
substr, str, pos);
     } else {
         writefln("the string '%s' was not found in '%s'", substr, 
str);
     }
}

void main() {
     string str = "one two three";
     str.find("two");
     str.find("");
     str.find("nine");
     str.find("n");
}
```
SDB at 79


More information about the Digitalmars-d-learn mailing list