Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Looking for string sequence within excel table with an unidentified number of spaces inbetween characters
조회 수: 7 (최근 30일)
이전 댓글 표시
Let's assume that I am looking for the sentence:
"This sentence has 27 characters"
inside a large excel table, which is composed on both string and numbers. However, this sentence could be written in different number os spaces inbetween the words, e.g.
"Thissentence has27 characters"
or
"Thi s sente nceha s27chara cte rs"
etc.
Is there a way to write just one command that covers all possible numbers of spaces inbetween characters, as long as the sequence always stays the same?
댓글 수: 0
답변 (1개)
Chris Perkins
2018년 1월 8일
편집: Chris Perkins
2018년 1월 8일
Hi Saeid,
You can remove all spaces using "regexprep" before doing the comparison. For example,
% Setting up sample strings
testStr = 'This sentence has 27 characters';
excelStr1 = 'Th is sen tence h as 27 charac ters';
excelStr2 = 'This sent en ceha s2 7ch aracters';
% Remove spaces
testStrNoSpace = regexprep(testStr,'\s+','')
excelStr1NoSpace = regexprep(excelStr1,'\s+','')
excelStr2 = regexprep(excelStr2,'\s+','')
Here, "regexprep" is replacing each instance of one or more space characters with an empty string, effectively removing the spaces.
After stripping the space characters, you can compare your strings normally to see if they match or not.
For more information regarding "regexprep", see the following documentation link:
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!