Getting index from strsplit or strfind in a null (00) terminated string
1 回表示 (過去 30 日間)
古いコメントを表示
I have a long string with chunks of data. Each data chunk is separated/terminated by null (hex 00). Right now I use strsplit(data, '\0') to split the string, which works fine, but it returns a cell array with data, however, I rather need the functionality of strfind and get a list of indices for where the string is split.
Example of data:
data_chunk "null/0x00" data_chunk "null/0x00" data_chunk "null/0x00"
I know the first chunk is obviously at index 0, but I would also like to get the indices of the remaining chunks.
Is it possible to use strfind and search for null?
2 件のコメント
Azzi Abdelmalek
2016 年 4 月 10 日
Post clearly your data, for example:
str='null/0x00'
Then explain what is the expected result
result=?
採用された回答
per isakson
2016 年 4 月 10 日
編集済み: per isakson
2016 年 4 月 10 日
What am I missing?
>> str = [char(0),'abc',char(0),'123',char(0)];
>> find( str==char(0) )
ans =
1 5 9
>> strfind( str, char(0) )
ans =
1 5 9
>> strsplit( str, '\0')
ans =
'' 'abc' '123' ''
4 件のコメント
per isakson
2016 年 4 月 11 日
編集済み: per isakson
2016 年 4 月 11 日
IMO: Explicit casting makes the code easier to read (and often faster).
>> ['B'+1, 67]
ans =
67 67
>> ['B', 67]
ans =
BC
>> ['B'+1, 'C']
ans =
CC
その他の回答 (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!