Re: sort a string

2020-05-02 Thread notna via Digitalmars-d-learn
On Friday, 1 May 2020 at 19:25:43 UTC, Steven Schveighoffer wrote: Nice! Yeah, I was sloppy in my newsgroup coding, sorry. One minor nit here, the to!(dchar[])(word.dup), the dup is not necessary, you are going to end up allocating a temporary array and throwing it away. Just do

Re: sort a string

2020-05-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/1/20 11:17 AM, drug wrote: 01.05.2020 18:04, notna пишет: hmmm, whích results in:   Error: cannot use [] operator on expression of type dchar try this: ```D import std; void main() {     string word = "Привет";     dchar[] line3 = to!(dchar[])(word.dup) // make a copy to get a range

Re: sort a string

2020-05-01 Thread notna via Digitalmars-d-learn
On Friday, 1 May 2020 at 15:17:53 UTC, drug wrote: 01.05.2020 18:04, notna пишет: hmmm, whích results in:  Error: cannot use [] operator on expression of type dchar try this: ```D import std; void main() { string word = "Привет"; dchar[] line3 = to!(dchar[])(word.dup) // make a

Re: sort a string

2020-05-01 Thread notna via Digitalmars-d-learn
On Friday, 1 May 2020 at 15:15:29 UTC, bachmeier wrote: On Friday, 1 May 2020 at 15:04:01 UTC, notna wrote: On Friday, 1 May 2020 at 12:29:26 UTC, Steven Schveighoffer wrote:     dchar[] line3 = sort(line2.to!(dchar[])); dchar[] line3 = sort(line2.to!dchar[]).release;

Re: sort a string

2020-05-01 Thread bachmeier via Digitalmars-d-learn
On Friday, 1 May 2020 at 15:04:01 UTC, notna wrote: On Friday, 1 May 2020 at 12:29:26 UTC, Steven Schveighoffer wrote:     dchar[] line3 = sort(line2.to!(dchar[])); dchar[] line3 = sort(line2.to!dchar[]).release; https://dlang.org/phobos/std_range.html#.SortedRange.release hmmm,

Re: sort a string

2020-05-01 Thread drug via Digitalmars-d-learn
01.05.2020 18:04, notna пишет: hmmm, whích results in:  Error: cannot use [] operator on expression of type dchar try this: ```D import std; void main() { string word = "Привет"; dchar[] line3 = to!(dchar[])(word.dup) // make a copy to get a range of mutable char

Re: sort a string

2020-05-01 Thread notna via Digitalmars-d-learn
On Friday, 1 May 2020 at 12:29:26 UTC, Steven Schveighoffer wrote:     dchar[] line3 = sort(line2.to!(dchar[])); dchar[] line3 = sort(line2.to!dchar[]).release; https://dlang.org/phobos/std_range.html#.SortedRange.release hmmm, whích results in: Error: cannot use [] operator on

Re: sort a string

2020-05-01 Thread drug via Digitalmars-d-learn
01.05.2020 15:29, Steven Schveighoffer пишет: Don't do this, use to!(dchar[]) as you have above. This will create incorrect dchars for non-ascii text. -Steve Argh, as always you're right. Funny that I never did that and sadly that I posted wrong code. Thank you, Steven, for correction of

Re: sort a string

2020-05-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/1/20 4:12 AM, drug wrote: 01.05.2020 10:38, Chris Katko пишет: I'm making anagrams. According to the nextPermutation() docs, I need to 'sort by less' to get all permutations. ... Except the doc page doesn't mention how to do that, nor does std.algorithm.sort show how to sort a string.

Re: sort a string

2020-05-01 Thread Chris Katko via Digitalmars-d-learn
On Friday, 1 May 2020 at 08:17:33 UTC, norm wrote: On Friday, 1 May 2020 at 07:38:53 UTC, Chris Katko wrote: [...] You need to convert the sort output to dchar[], e.g. --- dchar[] line3 = sort(line2.to!(dchar[])).to!(dchar[]); --- Cheers, Norm That works, thanks!

Re: sort a string

2020-05-01 Thread norm via Digitalmars-d-learn
On Friday, 1 May 2020 at 07:38:53 UTC, Chris Katko wrote: I'm making anagrams. According to the nextPermutation() docs, I need to 'sort by less' to get all permutations. ... Except the doc page doesn't mention how to do that, nor does std.algorithm.sort show how to sort a string. ... and the

Re: sort a string

2020-05-01 Thread drug via Digitalmars-d-learn
01.05.2020 10:38, Chris Katko пишет: I'm making anagrams. According to the nextPermutation() docs, I need to 'sort by less' to get all permutations. ... Except the doc page doesn't mention how to do that, nor does std.algorithm.sort show how to sort a string. ... and the google results on the