"strstr" D equivalent

Salih Dincer salihdb at hotmail.com
Fri Jul 29 15:39:16 UTC 2022


On Friday, 29 July 2022 at 14:14:54 UTC, pascal111 wrote:
> 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?!

This thread is about 
[UFCS](https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs). It can also be written as:

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

void findStr(string str) { }

void main()
{
   string str = "Hello, World!";
   str.indexOf("Wo").writeln; //7
   auto pos = "Hello, World!".indexOf("Wo");

   auto slice = str[pos..$-1];
   slice.writeln(": ", slice.length); // World: 5
   typeid(slice).writeln; // immutable(char)[]

   assert(str.indexOf("Wo") == pos);

   void find_str(string str) { }

   find_str(str);
   str.findStr();

   /* No compile:

   slice.typeid().writeln;

   slice.indedOf("Wo").assert();

   str.find_str();
   */
}
```

SDB at 79



More information about the Digitalmars-d-learn mailing list