how to delete the dot in a string

 採用された回答

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 ExchangeCharacters 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