Removing multiple substrings in a string

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 件のコメント

Andrea Cappannini
Andrea Cappannini 2020 年 7 月 20 日
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?
Andrea Cappannini
Andrea Cappannini 2020 年 7 月 20 日
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 ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by