Detect every second character from a string

13 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by