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!