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!