I have a string like this
String = 'AAAAAAAAAbbbbbbbbbbbbbbbbCCCCCCCCCCCCCCCCCddddddddddddddddddEEEEEEEEEEEE';
% I want to remove all the lowercase letters so I need some indexes to do it
[Start,End]=regexp(String,'[a-z]{1,}');
%Here it comes the problem
I do not know how to remove multiple substring from the same string. eraseBetween provide a way to index a substring but how to remove multiple ones?
Thank you in advance

 채택된 답변

Andrea Cappannini
Andrea Cappannini 2020년 7월 22일

0 개 추천

The answer I was searching for was:
x = 'AAAAAAAAAAAaaaaaaaaaaaTTTTTTTTTTTTTTTTsssssssssssTTTTTTTTTT'; % input
y = x; % initiallize result
[Start, End] = regexp(x, '[a-z]{1,}');
for k = numel(Start):-1:1 % note: from last to first
y(Start(k):End(k)) = []; % remove section
end

추가 답변 (1개)

madhan ravi
madhan ravi 2020년 7월 20일

0 개 추천

regexprep(String, '[a-z]*', '')

댓글 수: 4

I expressed in wrong way what I need Sorry. Let us suppose that I have the indexes of the substrings namely I now where the substrings start and end but. By these indexes I have to eliminate these substrings contained in the original substring. E.g. :
% I find the substrings position by regexp
[Start,End]= regexp(String,'[a-z]{1,}');
%I only know these positions and I have String that is very long and very difficult to analyze
%By these positions that are vector of numbers, I want to eliminate the substring that locates
%In those positions.
I hope I was clearer now. My fault sorry
madhan ravi
madhan ravi 2020년 7월 20일
Why touch your nose around the head instead of touching it directly?
It is a delicate question and I cannot give further details but I do need to know how to do it sorry.
madhan ravi
madhan ravi 2020년 7월 20일
You’re a funny guy xD.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by