Remove end folder part of string in MATLAB

时间:2017-07-10 15:17:02

标签: matlab

Say if we have this string

a = 'C:/my_folder/folder/mac/data/';

How can I use regexprep to reduce the string to:

'C:/my_folder/folder/mac/';

2 个答案:

答案 0 :(得分:0)

Actually, I found a way to do it.

[pathstr] = fileparts(a);
regexprep(pathstr, '(?<=/)[^/]*$', '')

答案 1 :(得分:0)

您可以尝试使用此方法在字符串结尾处剪切5个字符     a = a(1:结束-5)