how to divide a string by every 8 chars?

3 ビュー (過去 30 日間)
Roger
Roger 2014 年 6 月 9 日
コメント済み: Cedric 2014 年 6 月 9 日
str = 'sdkidkfl dkfke dkdke dka dkela32566 dsa321434 -6=0df3 302kd903kdl'
then divide it , How to make it ?

採用された回答

Image Analyst
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 件のコメント
Image Analyst
Image Analyst 2014 年 6 月 9 日
your string was not a multiple of 8 so reshape won't work.
Cedric
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 ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by