MATLAB Answers

write a code to sort string

76 views (last 30 days)
Aminata camara
Aminata camara on 17 Mar 2021
Commented: Aminata camara on 18 Mar 2021
how to I write a code for this problem:
Write a program that accepts a string from a user with the input function, chops that string into a series of tokens, sorts the tokens into ascending order, and prints them out.
this is what I wrote so far I dont know what to do
%Input a user string
str=input('Enter string:','s');
[token,remain]=strtok(str,',')
  2 Comments
Aminata camara
Aminata camara on 17 Mar 2021
that what the problem is saying, I understand it like when I'm writting a series of world
example if a user enter : anna,mimi,jen
the user will get
'anna'
'mimi'
'jen'
also I dont get what the problem is saying by then sort that information.

Sign in to comment.

Answers (1)

ANKUR KUMAR
ANKUR KUMAR on 17 Mar 2021
str=input('Enter string:','s');
strsplit(str,',')
On which basis you wish to sort strings? Is it alphabatically, or based on the length ?
  9 Comments
Aminata camara
Aminata camara on 18 Mar 2021
ooh I see now thank you for the great explanation

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!