フィルターのクリア

finding big letters and skip a line

3 ビュー (過去 30 日間)
Noa Prasquier
Noa Prasquier 2021 年 4 月 21 日
編集済み: Scott MacKenzie 2021 年 4 月 21 日
Hi,
I need to write a code that will help me find big letters in a string, and skip a line before the big letter(my string has to look like a poem with 5 lines)
Here the code I tried, I can't figure out what I need to write instead of ????
s="In the golden lightning Of the sunken sun,Oer which clouds are bright'ning, Thou dost float and run, Like an unbodied joy whose race is just begun";
for i=1:length(s)
if s(i)~=lower(s(i))
???
end
end

採用された回答

DGM
DGM 2021 年 4 月 21 日
Something like this:
s='In the golden lightning Of the sunken sun,Oer which clouds are bright''ning, Thou dost float and run, Like an unbodied joy whose race is just begun';
out=regexprep(s,'[A-Z]','\n$0')
  1 件のコメント
Scott MacKenzie
Scott MacKenzie 2021 年 4 月 21 日
編集済み: Scott MacKenzie 2021 年 4 月 21 日
Yup, there it is. Concise, elegant. Nice.

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

その他の回答 (1 件)

Scott MacKenzie
Scott MacKenzie 2021 年 4 月 21 日
編集済み: Scott MacKenzie 2021 年 4 月 21 日
There's probably a more elegant solution, but here's a first quick shot at this:
s="In the golden lightning Of the sunken sun,Oer which clouds are bright'ning, Thou dost float and run, Like an unbodied joy whose race is just begun";
c = char(s);
upper = isstrprop(s, 'upper');
k = find(upper);
k = [k length(c)+1];
for i=2:length(k)
fprintf('%s\n', c(k(i-1):k(i)-1));
end
Output:
In the golden lightning
Of the sunken sun,
Oer which clouds are bright'ning,
Thou dost float and run,
Like an unbodied joy whose race is just begun

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by