how to split strings equally with a rest

3 Ansichten (letzte 30 Tage)
Elie Elias
Elie Elias am 14 Okt. 2018
Bearbeitet: madhan ravi am 14 Okt. 2018
i want to split a string in equal parts like in this example:input='abcdefghijk' output='abc def ghi jk'

Akzeptierte Antwort

madhan ravi
madhan ravi am 14 Okt. 2018
Bearbeitet: madhan ravi am 14 Okt. 2018
input_string ='abcdefghijk' % don’t use variable name as input because it may contradict with built-in function
ns = numel(input_string);
n = 3;
Output = cellstr(reshape([input_string repmat(' ',1,ceil(ns/n)*n-ns)],n,[])')' % as cell
Output = char(Output) % as char
  3 Kommentare
Image Analyst
Image Analyst am 14 Okt. 2018
Please, in your answer, correct bad mistakes that the poster made, like calling the variable by the name of a built-in function like input() -- don't let them pass by without pointing them out.
madhan ravi
madhan ravi am 14 Okt. 2018
Thank you @sir Image Analyst rectified :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by