フィルターのクリア

token = strtok(str) Looking for Examples

5 ビュー (過去 30 日間)
Sabri Çetin
Sabri Çetin 2016 年 7 月 2 日
編集済み: Sabri Çetin 2016 年 7 月 2 日
token = strtok(str) parses input character vector str from left to right, returning part or all of that character vector in token. Using the white-space character as a delimiter, the token output begins at the start of str, skipping any delimiters that might appear at the start, and includes all characters up to either the next delimiter or the end of the character vector. White-space characters include space (ASCII 32), tab (ASCII 9), and carriage return (ASCII 13).
Could you please give an example with that format and explain what is going on? I checked the examples on the original webside but, there is no example in that format.
Any kind of help is appreciated. Thank you in advance.

採用された回答

Image Analyst
Image Analyst 2016 年 7 月 2 日
It's easier to use.
  3 件のコメント
Star Strider
Star Strider 2016 年 7 月 2 日
An alternative to strsplit that should work with most MATLAB versions is:
words = regexp(str, ' ', 'split')
with appropriate changes depending on the application. It adds an empty cell to the end, so the correct result is:
words(1:end-1)
Sabri Çetin
Sabri Çetin 2016 年 7 月 2 日
編集済み: Sabri Çetin 2016 年 7 月 2 日
strsplit is a very clear function, especially, useful for beginners, the alternative is not that complicated too.

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2016 年 7 月 2 日
My smiple-minded utility tokens that uses strtok --
function tok = tokens(s,d)
% Simple string parser returns tokens in input string s
%
% T=TOKENS(S) returns the tokens in the string S delimited
% by "white space". Any leading white space characters are ignored.
%
% TOKENS(S,D) returns tokens delimited by one of the
% characters in D. Any leading delimiter characters are ignored.
% Get initial token and set up for rest
if nargin==1
[tok,r] = strtok(s);
while ~isempty(r)
[t,r] = strtok(r);
tok = strvcat(tok,t);
end
else
[tok,r] = strtok(s,d);
while ~isempty(r)
[t,r] = strtok(r,d);
tok = strvcat(tok,t);
end
end
  1 件のコメント
Sabri Çetin
Sabri Çetin 2016 年 7 月 2 日
This is a great example! Also, it might be very useful depending on the context.

サインインしてコメントする。

カテゴリ

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