How can i remove a previous character present before the underscore including the underscore also.
3 ビュー (過去 30 日間)
古いコメントを表示
I need to make my_john_sam as mjohsam. I need to remove underscore along with the character present just before underscore.
thanks
0 件のコメント
回答 (2 件)
per isakson
2015 年 10 月 1 日
編集済み: per isakson
2015 年 10 月 1 日
Replace any one character followed by one underscore with empty string
>> regexprep( 'my_john_sam', '._', '' )
ans =
mjohsam
2 件のコメント
per isakson
2015 年 10 月 1 日
編集済み: per isakson
2015 年 10 月 1 日
>> cssm('my_john_sam')
ans =
mjohsam
>> cssm('a string without underscore')
ans =
a string without underscore
where
function str = cssm( str )
ixs = strfind(str,'_');
for jj = fliplr( ixs )
z = str(jj-1:jj);
str = strrep(str,z,'');
end
end
Walter Roberson
2015 年 10 月 1 日
c='my_john_sam';
idx = c == '_';
c( idx|[idx(2:end), false]) = [];
or
c='my_john_sam';
idx = find(c == '_');
c([idx, idx-1]) = [];
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!