how to divide a string by every 8 chars?
1 次查看(过去 30 天)
显示 更早的评论
str = 'sdkidkfl dkfke dkdke dka dkela32566 dsa321434 -6=0df3 302kd903kdl'
then divide it , How to make it ?
0 个评论
采纳的回答
Image Analyst
2014-6-9
编辑:Image Analyst
2014-6-9
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 个评论
Cedric
2014-6-9
The way I understood the question was that spaces were not separators, and that the OP really needed to extract segments of 8 chars.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!