필터 지우기
필터 지우기

How to remove unnecessary character from a string

조회 수: 7 (최근 30일)
Anudeep
Anudeep 2020년 4월 9일
댓글: Ameer Hamza 2020년 4월 9일
I have a string,
'This may be our situation. It is similarly fantastical to expect people who cannot afford food\xc2\xa0\xe2\x80\x94 as will soon be the case for many more\xc2\xa0\xe2\x80\x94 to practice personal hygiene. You can\xe2\x80\x99t eat soap. If you are starving, you won\xe2\x80\x99t buy it.'
I have to remove the unnecessary string like, '\xc2\xa0\xe2\x80\x94' from the string. The patter which I can observe is this unnecessary string starts with '\' and ends with a number.
Thanks so much for the help.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 9일
str = ['This may be our situation. It is similarly fantastical to ' ...
'expect people who cannot afford food\xc2\xa0\xe2\x80\x94 as will ' ...
'soon be the case for many more\xc2\xa0\xe2\x80\x94 to practice ' ...
'personal hygiene. You can\xe2\x80\x99t eat soap. If you are starving, ' ...
'you won\xe2\x80\x99t buy it.'];
new_str = regexprep(str, '\\[a-z0-9]{3}', '');
  댓글 수: 2
Anudeep
Anudeep 2020년 4월 9일
This worked for me. Thanks Ameer.
Ameer Hamza
Ameer Hamza 2020년 4월 9일
Glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by