How do I take the first word out of every word in a string and make those letters into a combined word

1 回表示 (過去 30 日間)
I want to enter a string 'Control Air Pollution' and call a function to get another string 'CAP'; which is the first letter of every word in the original string. How do we do this without inbuilt functions.

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 12 月 7 日
  3 件のコメント
Walter Roberson
Walter Roberson 2015 年 12 月 8 日
Note that regexp considers digits and underscores to be "word" characters, but not apostrophe, so it would miss the apostrophe in the English word 'twas but the apostrophe is arguably the first letter of the word.
Guillaume
Guillaume 2015 年 12 月 8 日
Yes, I assumed that the string did not contain any punctuation or special character as it becomes a bit unclear as to what should be included. It is of course fairly trivial to modify the regexp to include or exclude any character
string = '''twas the night before christmas';
string(regexp(string, '(?<=^|\s).')) %returns 'tnbc

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

カテゴリ

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