Sort characters in string

Fredrik Boulund fredrik.boulund at gmail.com
Wed Dec 6 08:59:09 UTC 2017


Hi,

I'm having some trouble sorting the individual characters in a 
string. Searching around, I found this thread 
(http://forum.dlang.org/post/mailman.612.1331659665.4860.digitalmars-d-learn@puremagic.com) about a similar issue, but it feels quite old so I wanted to check if there is a clear cut way of sorting the characters of a string nowadays?

I was expecting to be able to do something like this:

string word = "longword";
writeln(sort(word));

But that doesn't work because I guess a string is not the type of 
range required for sort?
I tried converting it to a char[] array (to!(char[])(word)) but 
that doesn't seem work either. I get:

Error: template std.algorithm.sorting.sort cannot deduce function 
from argument types !()(char[])

Best regards,
Fredrik


More information about the Digitalmars-d-learn mailing list