How to replace only one instance in a certain string
이전 댓글 표시
I am trying to use strrep() to replace the first 'e' with nothing '' and leave the second one alone in the following string:
x = 'e-8.5e-5';
y = strrep(x,'e','');
desired_final_ans = '-8.5e-5';
Is there a way to skip instances in strrep()?
채택된 답변
추가 답변 (1개)
Image Analyst
2021년 10월 18일
Here's one way:
eLocations = strfind(x, 'e')
x(eLocations(1)) = [] % Replace first e with null (in other words, delete it).
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!