- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Sorting words in a string
I would like to sort words alphabetically in a string. I am stuck trying to get the list back into one string.
string= "sort this sentence";
string_list = sort list(words(string )); // string_list = {"sentence", "sort", "this"};
Sorted_string = (string_list); // not sure how to create Sorted_string = "sentence sort this"
show(string, string_list, Sorted_string);
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Sorting words in a string
I still would suggest using Concat Items() in cases like this
Names Default To Here(1);
string = "sort this sentence";
string_list = Sort List(Words(string));
Sorted_string = Concat Items(string_list, " ");
Show(string, string_list, Sorted_string);
string = "sort this sentence";
string_list = {"sentence", "sort", "this"};
Sorted_string = "sentence sort this";
-Jarmo
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Sorting words in a string
In JMP you can use Concat Items()
Names Default To Here(1);
Concat Items({"www", "jmp", "com"}, "."); //"www.jmp.com"
-Jarmo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Sorting words in a string
Thanks you got me on the right track.
string= "sort this sentence";
string_list = sort list(words(string));
sorting_string = "";
for(i=1, i<=nitems(string_list), i++,
if(i<nitems(string_list),
Sorting_string = concat(sorting_string, string_list[i], " ");
,
Sorting_string = concat(sorting_string, string_list[i]);
);
);
show(string, string_list, Sorting_string);----------------Log:string = "sort this sentence";string_list = {"sentence", "sort", "this"};Sorting_string = "sentence sort this";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Sorting words in a string
I still would suggest using Concat Items() in cases like this
Names Default To Here(1);
string = "sort this sentence";
string_list = Sort List(Words(string));
Sorted_string = Concat Items(string_list, " ");
Show(string, string_list, Sorted_string);
string = "sort this sentence";
string_list = {"sentence", "sort", "this"};
Sorted_string = "sentence sort this";
-Jarmo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Sorting words in a string
Perfect! Thanks!