If i have a string =
" 30th Birthday WORLDCUP34 WORLDCUP'34 '04 "
and i want the output to be only =
" Birthday " ,
then how can i go forward to achieve such by removing all expressions containing numbers with it.

 採用された回答

Birdman
Birdman 2018 年 1 月 19 日
編集済み: Birdman 2018 年 1 月 19 日

0 投票

One approach:
s1="30th Birthday WORLDCUP34 WORLDCUP'34 '04";
str=strsplit(s1,' ');
result=str(cellfun(@isempty,(regexp(str,'\d+'))))

5 件のコメント

HIRAKJYOTI BASUMATARY
HIRAKJYOTI BASUMATARY 2018 年 1 月 19 日
Thanks a lot. Also is there is a way if the expression was s1="30th Birthday WORLDCUP34 WORLDCUP'34 '04 Messi"; and i want the output in a single cell as "Birthday Messi" , both in a single cell .
Birdman
Birdman 2018 年 1 月 19 日
編集済み: Birdman 2018 年 1 月 19 日
s1="30th Birthday WORLDCUP34 WORLDCUP'34 '04 Messi";
str=strsplit(s1,' ');
result=strjoin(str(cellfun(@isempty,(regexp(str,'\d+')))))
Use strjoin different than my first answer.
Jan
Jan 2018 年 1 月 19 日
@Birdman: cellfun works faster with the builtin commands, which are specified as chars, here: cellfun('isempty', ...).
@HIRAKJYOTI BASUMATARY: Did you try Birdman's solution with your new string? It should run directly. What does this mean: "output in a single cell as "Birthday Messi" , both in a single cell"?
Birdman
Birdman 2018 年 1 月 19 日
Ok Jan, thanks. It just takes time to get used to working with cellfun.
HIRAKJYOTI BASUMATARY
HIRAKJYOTI BASUMATARY 2018 年 1 月 19 日
@Birdman Sir and @Jan Simon Sir , thanks a lot for the guidance. Yes @Jan simon sir, i meant in a single cell.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeBirthdays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by