您好。
这里有一个2x1字符串:
A = ["CHAPTER 1. Random info in middle one, Random info still continues. 1";...
"CHAPTER 2. Random info in middle two. Random info still continues. 1"];
如何删除";第#章";,最后一个数字和空格后面的空格?这是我的尝试:
%PlanA
for n=1:2
% Delete "Chapter+Nr"
A(n,1) = erase(A,'(CHAPTER d)');
% Delete last nr 1 at end
A(n,1) = erase(A,'d');
end
%PlanB
A(strcmp(A, 'CHAPTER d')) = []
我不知道为什么这不起作用?
感谢您的帮助谢谢
您可以为此使用regexprep:
regexprep(A,'CHAPTER d+. (.+) d$','$1')
ans =
2×1 string array
"Random info in middle one, Random info still continues."
"Random info in middle two. Random info still continues."