delete an element from string
64 次查看(过去 30 天)
显示 更早的评论
hi
I have this string:
str = ["a" "b" "c"]
which gives:
"a" "b" "c"
how can I have this new string with the previouse one:
new_str = "a" "c"
in other words, I want to delete "b" completely.
I have tried erase but with that I will have:
"a" "" "c"
thanks in advance.
0 个评论
采纳的回答
DGM
2022-5-21
How do you intend to identify the thing you want to delete? Do you simply want to delete the second string in the array?
str = ["a" "b" "c"];
str(2) = []
Or do you want to delete all (or the first) instance of the string "b" in the array?
str = ["a" "b" "c"];
idx = strcmp(str,"b");
str(idx) = []
2 个评论
更多回答(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!