Removing Part of A String

1 回表示 (過去 30 日間)
Syed Abbas
Syed Abbas 2011 年 12 月 27 日
Hi, I have a string of numbers of in the format '7646 89:89'. I basically want to remove the numbers following the white space e.g I want '7646 89:89' to become '7649'. Thanks

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 12 月 27 日
s='7646 89:89';
d=textscan(s,'%f*');
d=d{1};
  1 件のコメント
Jan
Jan 2011 年 12 月 27 日
TEXTSCAN is very powerful, and in consequence it is slow.

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

その他の回答 (1 件)

Jan
Jan 2011 年 12 月 27 日
Faster than the very powerful TEXTSCAN:
s = '7646 89:89';
d = strtok(s, ' ');
Or simply:
d = strtok(s);
Or:
index = strfind(s, ' ');
d = s(1:index(1));
  1 件のコメント
Syed Abbas
Syed Abbas 2011 年 12 月 27 日
Thanks a lot!

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

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by