필터 지우기
필터 지우기

if i have a string say 'ec john nick' .how to delete ec and retain 'john nick'?

조회 수: 1 (최근 30일)
.

채택된 답변

John D'Errico
John D'Errico 2016년 1월 4일
편집: John D'Errico 2016년 1월 4일
Not at all clear what you REALLY want to do here.
If all you want to do is to remove the first "word" from the string, then find the first occurrence of a space after a character. Then delete all up to that point. Any of these will help you out:
help regexp
help strfind
help find
I recommend regexp as the best way though.
If your question is to remove the explicit character string 'ec', then strfind will again help you, as will regexp.
If you wish to find the words 'john nick' and retain only that part, then again regexp, strfind will solve it.
As far as deleting part of a string, a string is just like any vector. You delete elements like this:
A = rand(1,10);
A(1:3) = [];
So that deleted the first three elements of A.
  댓글 수: 4
John D'Errico
John D'Errico 2016년 1월 4일
Ok. so then use regexp to find the first occurrence of a character, followed by a space. Then delete everything up to that point. Or keep everything after that point, which is equivalent.
Image Analyst
Image Analyst 2016년 1월 4일
If all the person's names are in a single string, then you can split it up with John's handy "allwords" utility: http://www.mathworks.com/matlabcentral/fileexchange/27184-allwords to split the name up into first, middle, and last name, and then use strcmpi() to compare the strings you want to compare..

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

추가 답변 (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