Why does "strcmp" sometimes return non-equal when apparently they are the same?
조회 수: 6 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2024년 10월 30일
답변: MathWorks Support Team
2024년 10월 31일
Why does "strcmp" sometimes return non-equal when apparently the strings are the same?
채택된 답변
MathWorks Support Team
2024년 10월 30일
This could be caused by the presence of invisible Unicode characters.
Many invisible characters that can appear as a space when printed, but there are also characters like the Zero-Width Non-breaking Space (ZWNBSP; Unicode char U+FEFF) that are completely invisible and don't take up space.
It can happen that such characters are read from data sources and can lead to unexpected behavior for example with string comparison.
Even when they are invisible, they can still be filtered out by the strrep function:
Identifying that such a character is present is probably the biggest challenge when such an issue is found or noticed. The strlength function accounts for such characters.
See the attached example that is using the mentioned ZWNBSP.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!