How to replace only one instance in a certain string
61 ビュー (過去 30 日間)
古いコメントを表示
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()?
採用された回答
the cyclist
2021 年 10 月 18 日
If you are certain that the first e is the first character of the string, then this will do it:
x = 'e-8.5e-5'
y = regexprep(x,'^e','')
The '^' indicates that the regular expression has to start the string.
0 件のコメント
その他の回答 (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).
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!