Detect every second character from a string

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일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

Bob
2014년 2월 3일

편집:

Bob
2014년 2월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by