cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
justvince
Level III

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
jthi
Super User

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

View solution in original post

4 REPLIES 4
jthi
Super User

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
justvince
Level III

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";
jthi
Super User

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
justvince
Level III

Re: Sorting words in a string

Perfect! Thanks!

Recommended Articles