Replacing String Values By Position
10 次查看(过去 30 天)
显示 更早的评论
I wanted to know how I could assign new values to a string based on their position. For example, if I have the following string 'test rest' and I do a strfind('test rest', 'e') and am given the output 2 7. How can I use that to replace the 'e' with another arbitrary value such as 'r', so that my output reads 'trst rrst.' I'd like to do this with out using something like strrep()
Thank you.
0 个评论
采纳的回答
Matt Fig
2012-9-15
You don't need to use linear indexing (STRFIND) here at all. Just use logical indexing.
str = 'test rest';
str(str=='e')='r'
0 个评论
更多回答(1 个)
另请参阅
类别
在 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!