how to divide a string by every 8 chars?

1 visualización (últimos 30 días)
Roger
Roger el 9 de Jun. de 2014
Comentada: Cedric el 9 de Jun. de 2014
str = 'sdkidkfl dkfke dkdke dka dkela32566 dsa321434 -6=0df3 302kd903kdl'
then divide it , How to make it ?

Respuesta aceptada

Image Analyst
Image Analyst el 9 de Jun. de 2014
Editada: Image Analyst el 9 de Jun. de 2014
str = 'sdkidkfl dkfke dkdke dka dkela32566 dsa321434 -6=0df3 302kd903kdl'
allwords(str)
In the command window:
str =
sdkidkfl dkfke dkdke dka dkela32566 dsa321434 -6=0df3 302kd903kdl
ans =
'sdkidkfl' 'dkfke' 'dkdke' 'dka' 'dkela32566' 'dsa321434' '-6=0df3' '302kd903kdl'
If you want every 8 (or partial if there are not enough), then try this:
counter = 1;
for index = 1 : 8 : length(str)
lastIndex = min(index+7, length(str));
ca{counter} = str(index:lastIndex);
counter = counter + 1;
end
celldisp(ca)
  5 comentarios
Image Analyst
Image Analyst el 9 de Jun. de 2014
your string was not a multiple of 8 so reshape won't work.
Cedric
Cedric el 9 de Jun. de 2014
The way I understood the question was that spaces were not separators, and that the OP really needed to extract segments of 8 chars.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by