フィルターのクリア

How to reference entire substring as a string?

2 ビュー (過去 30 日間)
Ted Baker
Ted Baker 2019 年 11 月 27 日
コメント済み: Stephen23 2019 年 11 月 27 日
I have an array of strings in a 4x1 cell format, called textarr, as below:
ExA
ExB
ExC
ExD.exe
I would like to remove the .exe, so I initially tried:
textarr(4) = textarr(4)(1:end-4);
But Matlab did not like the double brackets on the right hand side.
I then tried a method using a temporary variable, like:
lasttemp = textarr(4);
lasttemp = lasttemp(1:end-4);
But this just results in lasttemp becoming a 1x0 cell...
I suspect I am confusing the String itself with elements of a string array. How can I address a String inside a specific element of an array?
  1 件のコメント
Stephen23
Stephen23 2019 年 11 月 27 日
If those strings represent filenames then using indexing is not a robust solution (because file extensions do NOT all have three characters!). The simple, robust, easy MATLAB solution to remove the file extensions is to use fileparts.

サインインしてコメントする。

採用された回答

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019 年 11 月 27 日
solution:
textarr={'ExA';
'ExB';
'ExC';
'ExD.exe'}
textarr=strrep(textarr,'.exe','')%remove
  1 件のコメント
Ted Baker
Ted Baker 2019 年 11 月 27 日
Thank you very much for the fast answer, it works perfectly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by