Detect every second character from a string

13 ビュー (過去 30 日間)
Bob
Bob 2014 年 2 月 3 日
編集済み: Bob 2014 年 2 月 5 日
How can I detect every second character of a string?
Thanks in advance!
  1 件のコメント
Thomas
Thomas 2014 年 2 月 3 日
Is this a homework problem? What have tried so far and where are you getting stuck?

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

採用された回答

Iain
Iain 2014 年 2 月 3 日
編集済み: Iain 2014 年 2 月 3 日
This counts spaces & punctuation as characters (starting with the 1st character).
string_var = 'The sun is shining. I feel good.';
answer = string_var(1:2:end)
This eliminates periods:
string_var = 'The sun is shining. I feel good.';
string_var(string_var == '.') = '';
answer = string_var(1:2:end)
Change the . to whatever character you want to eliminate. You want a space.

その他の回答 (0 件)

カテゴリ

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