Re: sorting a string

2017-07-15 Thread Gerald Jansen via Digitalmars-d-learn
On Friday, 14 July 2017 at 20:52:54 UTC, Jonathan M Davis wrote: And of course, this whole issue is incredibly confusing to anyone coming to D - especially those who aren't well-versed in Unicode. Right on. Thanks for your very clear summary (the whole thing, not just the last line!). Much

Re: sorting a string

2017-07-14 Thread ag0aep6g via Digitalmars-d-learn
On 07/15/2017 04:33 AM, Namal wrote: Why does it have to be char[]? auto bytes = line.representation.dup; bytes.sort; string result = bytes.assumeUTF; works too. That's a compiler bug. The code should not compile, because now you can mutate `result`'s elements through `bytes`. But

Re: sorting a string

2017-07-14 Thread Namal via Digitalmars-d-learn
On Friday, 14 July 2017 at 17:23:41 UTC, Steven Schveighoffer wrote: import std.string: representation, assumeUTF; import std.algorithm: sort; auto bytes = line.representation.dup; bytes.sort; auto result = bytes.assumeUTF; // result is now char[] Why does it have to be char[]? auto

Re: sorting a string

2017-07-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 14, 2017 7:50:17 PM MDT Anton Fediushin via Digitalmars-d- learn wrote: > On Friday, 14 July 2017 at 17:23:41 UTC, Steven Schveighoffer > > wrote: > > Don't do this, because it's not what you think. It's not > > actually calling std.algorithm.sort, but the builtin array sort > >

Re: sorting a string

2017-07-14 Thread ag0aep6g via Digitalmars-d-learn
On 07/14/2017 09:50 PM, Anton Fediushin wrote: But why? This should be true for `char[]`, isn't it? - if ((ss == SwapStrategy.unstable && (hasSwappableElements!Range || hasAssignableElements!Range) || ss != SwapStrategy.unstable && hasAssignableElements!Range) && isRandomAccessRange!Range

Re: sorting a string

2017-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/17 3:50 PM, Anton Fediushin wrote: On Friday, 14 July 2017 at 17:23:41 UTC, Steven Schveighoffer wrote: Don't do this, because it's not what you think. It's not actually calling std.algorithm.sort, but the builtin array sort property. This will be going away soon. This sucks. I know,

Re: sorting a string

2017-07-14 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 14 July 2017 at 17:23:41 UTC, Steven Schveighoffer wrote: Don't do this, because it's not what you think. It's not actually calling std.algorithm.sort, but the builtin array sort property. This will be going away soon. This sucks. I know, that `.sort` will be removed, but I thought

Re: sorting a string

2017-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/17 1:42 PM, Seb wrote: On Friday, 14 July 2017 at 17:28:29 UTC, Namal wrote: On Friday, 14 July 2017 at 16:43:42 UTC, Anton Fediushin wrote: On Friday, 14 July 2017 at 15:56:49 UTC, Namal wrote: Thx Steve! By sorting string I mean a function or series of functions that sorts a string

Re: sorting a string

2017-07-14 Thread Seb via Digitalmars-d-learn
On Friday, 14 July 2017 at 17:28:29 UTC, Namal wrote: On Friday, 14 July 2017 at 16:43:42 UTC, Anton Fediushin wrote: On Friday, 14 July 2017 at 15:56:49 UTC, Namal wrote: Thx Steve! By sorting string I mean a function or series of functions that sorts a string by ASCII code, "cabA"

Re: sorting a string

2017-07-14 Thread Namal via Digitalmars-d-learn
On Friday, 14 July 2017 at 16:43:42 UTC, Anton Fediushin wrote: On Friday, 14 July 2017 at 15:56:49 UTC, Namal wrote: Thx Steve! By sorting string I mean a function or series of functions that sorts a string by ASCII code, "cabA" to "Aabc" for instance. import std.algo

Re: sorting a string

2017-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/17 12:43 PM, Anton Fediushin wrote: On Friday, 14 July 2017 at 15:56:49 UTC, Namal wrote: Thx Steve! By sorting string I mean a function or series of functions that sorts a string by ASCII code, "cabA" to "Aabc" for instance. import std.algorithm : sort; import

Re: sorting a string

2017-07-14 Thread Anton Fediushin via Digitalmars-d-learn
On Friday, 14 July 2017 at 15:56:49 UTC, Namal wrote: Thx Steve! By sorting string I mean a function or series of functions that sorts a string by ASCII code, "cabA" to "Aabc" for instance. import std.algorithm : sort; import std.stdio : writeln; "cabA".du

Re: sorting a string

2017-07-14 Thread Namal via Digitalmars-d-learn
cii whitespace, you can do it a bit more efficiently, but it's not easy. About the string sorting, you'd have to be more specific. -Steve Thx Steve! By sorting string I mean a function or series of functions that sorts a string by ASCII code, "cabA" to "Aabc" for instance.

Re: sorting a string

2017-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
t a bit more efficiently, but it's not easy. About the string sorting, you'd have to be more specific. -Steve

sorting a string

2017-07-14 Thread Namal via Digitalmars-d-learn
Is there a 'easy' way to sort a string in D like it is possible in Python? Also how can I remove whitespace between characters if I am reading a line from a file and safe it as a string? string[] buffer; foreach (line ; File("test.txt").byLine) buffer ~= line.to!string;