On Friday, 29 July 2022 at 13:44:47 UTC, Salih Dincer wrote:
**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@79

Ok! I have a problem now in understanding these new syntax. You said "str.indexOf(substr)", so I can say that the first parameter of "indexOf" is "str" itself, and second parameter is "substr" and rather than writing it in the form "indexOf(str, substr)" you written it like "str.indexOf(substr)", am I right? and if I'm right, with returning back to the definitions of "indexOf" @ https://dlang.org/phobos/std_string.html#.indexOf we won't find that there is a definition for it with just two parameters, so from where you got this new definition of this function?!

Reply via email to