Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Comparing two equal strings doesnt work
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a list of strings (containing hockey player names) and I want to find the index for a specific name.I never had such an easy problem before and it is driving my insane.
I tried this:
player and index are both "Connor McDavid"
player = Player(1);
index1 = string(200);
logic = strcmp(index1 ,player);
Here are screenshots too ensure that they contain the same value.
![Unbenannt.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/243616/Unbenannt.png)
![Unbenannt.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/243617/Unbenannt.png)
logic should return a 1 but it returns 0. I tried == too but it doesnt help.
Pls help me, i dont know what to do anymore.
댓글 수: 9
Walter Roberson
2019년 10월 20일
160 is U+00A0, "non-breaking space"
player = replace(player, char(160), ' ');
index1 = replace(index1, char(160), ' ');
but it would probably make more sense to replace all of the 160 in your data source (perhaps immediately after retrieving it) instead of doing the replacement each iteration.
답변 (1개)
Prasad Parameswaran
2019년 10월 22일
편집: Prasad Parameswaran
2019년 10월 22일
This can be solved by using the "ismember" function, refer the below example:
A = ["John"; "Lee" ; "James"; "Lee"];
B = "Lee";
index = ismember(A,B)
The output is
index =
4×1 logical array
0
1
0
1
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!