Sort characters in NSString into alphabetical order

前端 未结 4 1127
醉话见心
醉话见心 2020-12-10 15:57

I\'m trying to re-arrange words into alphabetical order. For example, tomato would become amoott, or stack would become ackst.

I\'ve found some methods to do this in

4条回答
  •  情书的邮戳
    2020-12-10 16:40

    I think separate the string to an array of string(each string in the array contains only one char from the original string). Then sort the array will be OK. This is not efficient but is enough when the string is not very long. I've tested the code.

    NSString *str = @"stack";
    NSMutableArray *charArray = [NSMutableArray arrayWithCapacity:str.length];
    for (int i=0; i

提交回复
热议问题