Re: How to find the right function in the Phobos library?

2024-08-16 Thread Ron Tarrant via Digitalmars-d-learn
On Saturday, 17 August 2024 at 05:28:37 UTC, Bruce wrote: Example. I want to find the index of an item in an array. ``` import std.stdio; import std.string; void main() { string text = "Hello, World!"; string searchSubstring = "World"; ptrdiff_t index = text.indexOf(searchSubstring);

Re: How to find the right function in the Phobos library?

2024-08-16 Thread monkyyy via Digitalmars-d-learn
On Saturday, 17 August 2024 at 06:11:58 UTC, Bruce wrote: On Saturday, 17 August 2024 at 05:42:42 UTC, monkyyy wrote: On Saturday, 17 August 2024 at 05:28:37 UTC, Bruce wrote: It's the correct name for the wrong function Are you saying this is wrong? auto i = arr.countUntil("ha"); yes ```d

Re: How to find the right function in the Phobos library?

2024-08-16 Thread Bruce via Digitalmars-d-learn
On Saturday, 17 August 2024 at 05:42:42 UTC, monkyyy wrote: On Saturday, 17 August 2024 at 05:28:37 UTC, Bruce wrote: It's the correct name for the wrong function Are you saying this is wrong? auto i = arr.countUntil("ha");

Re: create fixed length string of characters

2024-08-16 Thread Bruce via Digitalmars-d-learn
On Friday, 16 August 2024 at 11:37:08 UTC, Nick Treleaven wrote: ```d // use a fixed array: immutable char[60] a = '-'; string s = a.dup; // copy to heap, assuming you need the data to escape (use a[] otherwise) s.writeln(); This seems to work without having to make a string dup. I just w

Re: How to find the right function in the Phobos library?

2024-08-16 Thread monkyyy via Digitalmars-d-learn
On Saturday, 17 August 2024 at 05:28:37 UTC, Bruce wrote: This seems to work but now I'm concerned. Why was it so hard to find? What is the best way to search for a function in the Phobos library? It's the correct name for the wrong function If you use it on unicode strings or filters it's ju

Re: Performance O(??) for associative array lookup

2024-08-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 14 August 2024 at 07:48:58 UTC, Cecil Ward wrote: Does D give any guarantees for performance order-something ? What’s the current lib implementation like? It is amortized O(1), like most hash implementations. -Steve

Re: create fixed length string of characters

2024-08-16 Thread Renato Athaydes via Digitalmars-d-learn
On Friday, 16 August 2024 at 18:00:25 UTC, Renato Athaydes wrote: On Friday, 16 August 2024 at 13:30:53 UTC, IchorDev wrote: On Friday, 16 August 2024 at 11:37:08 UTC, Nick Treleaven wrote: On Friday, 16 August 2024 at 06:15:18 UTC, Bruce wrote: ```d string s = a.dup; // copy to heap, assuming

Re: create fixed length string of characters

2024-08-16 Thread Renato Athaydes via Digitalmars-d-learn
On Friday, 16 August 2024 at 13:30:53 UTC, IchorDev wrote: On Friday, 16 August 2024 at 11:37:08 UTC, Nick Treleaven wrote: On Friday, 16 August 2024 at 06:15:18 UTC, Bruce wrote: ```d string s = a.dup; // copy to heap, assuming you need the data to escape (use a[] otherwise) s.writeln(); ```

Re: create fixed length string of characters

2024-08-16 Thread IchorDev via Digitalmars-d-learn
On Friday, 16 August 2024 at 15:58:31 UTC, Nick Treleaven wrote: On Friday, 16 August 2024 at 13:30:53 UTC, IchorDev wrote: On Friday, 16 August 2024 at 11:37:08 UTC, Nick Treleaven wrote: On Friday, 16 August 2024 at 06:15:18 UTC, Bruce wrote: ```d string s = a.dup; // copy to heap, assuming y

Re: create fixed length string of characters

2024-08-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, August 16, 2024 10:37:45 AM MDT Nick Treleaven via Digitalmars-d- learn wrote: > On Friday, 16 August 2024 at 16:30:09 UTC, Jonathan M Davis wrote: > > Whether the result of dup is then able to be implicitly > > converted to immutable based on whether the operation is pure > > depends on

Re: create fixed length string of characters

2024-08-16 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 16 August 2024 at 16:30:09 UTC, Jonathan M Davis wrote: Well, you if you use dup, you're asking for a mutable array, whereas if you use idup, you're asking for an immutable array. Yes, `idup` may be needed e.g. for overloads varying on mutability. Whether the result of dup is then

Re: create fixed length string of characters

2024-08-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, August 16, 2024 9:58:31 AM MDT Nick Treleaven via Digitalmars-d- learn wrote: > On Friday, 16 August 2024 at 13:30:53 UTC, IchorDev wrote: > > On Friday, 16 August 2024 at 11:37:08 UTC, Nick Treleaven wrote: > >> On Friday, 16 August 2024 at 06:15:18 UTC, Bruce wrote: > >> ```d > >> stri

Re: create fixed length string of characters

2024-08-16 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 16 August 2024 at 13:30:53 UTC, IchorDev wrote: On Friday, 16 August 2024 at 11:37:08 UTC, Nick Treleaven wrote: On Friday, 16 August 2024 at 06:15:18 UTC, Bruce wrote: ```d string s = a.dup; // copy to heap, assuming you need the data to escape (use a[] otherwise) s.writeln(); ```

Re: create fixed length string of characters

2024-08-16 Thread IchorDev via Digitalmars-d-learn
On Friday, 16 August 2024 at 11:37:08 UTC, Nick Treleaven wrote: On Friday, 16 August 2024 at 06:15:18 UTC, Bruce wrote: ```d string s = a.dup; // copy to heap, assuming you need the data to escape (use a[] otherwise) s.writeln(); ``` I think you meant `idup`? `dup` will make it mutable.

Re: create fixed length string of characters

2024-08-16 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 16 August 2024 at 06:15:18 UTC, Bruce wrote: Is there an easy way to create a 60 character string in D? Like in Python... ul = '-'*60 2 ways: ```d // use a fixed array: immutable char[60] a = '-'; string s = a.dup; // copy to heap, assuming you need the data to escape (use a[] othe