채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 1월 21일
편집: Andrei Bobrov 2014년 1월 21일

2 개 추천

a = 'bbc.ed.123.f.txt';
regexprep(a,{'\.','txt'},{'','.txt'})
or
[strrep(a(1:end-4),'.',''),'.txt']

댓글 수: 1

Roger
Roger 2014년 1월 22일
if i also want to replace '-' with '_',and ' 'with '',i should do like this
a=[strrep(a(1:end-4),'.',''),'.txt'];
a=[strrep(a(1:end-4),'-','_'),'.txt'];
a=[strrep(a(1:end-4),' ',''),'.txt'];
is there easy way?

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

추가 답변 (1개)

ES
ES 2014년 1월 21일

2 개 추천

you have to handle the last dot(before file extension) and the other dots separately.
str='bbc.ed.123.f.txt';
idx=strfind(str,'.');
new_str=[strrep(str(1:idx(end)-1),'.',''),str(idx(end):end)];%idx(end) is the position of the last dot!

카테고리

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

태그

질문:

2014년 1월 21일

댓글:

2014년 1월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by