필터 지우기
필터 지우기

Insert underscore into the string

조회 수: 8 (최근 30일)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2016년 8월 23일
답변: Azzi Abdelmalek 2016년 8월 23일
a = datestr(now,31)
a = 2016-08-23 09:15:47
a = regexprep(a,'[^a-zA-Z0-9]','') = 20160823091547
a(1:2) = []
a = '160823091547'
Now i need to insert the underscore after the sixth element in the string
160823_091547
how can i do this?
is it possible to optimize the above steps or my approach is correct?
Thanks a lot

채택된 답변

Guillaume
Guillaume 2016년 8월 23일
Using regexprep, this would be one of the many ways to do it:
a = regexprep(datestr(now, 31), '..(..)-(..)-(..) (..):(..):(..)', '$1$2$3_$4$5$6')
But even simpler, why not ask datestr to output exactly what you want directly:
a = datestr(now, 'yymmdd_HHMMSS')

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 8월 23일
a=[a(1:6) '_' a(7:end)]

Azzi Abdelmalek
Azzi Abdelmalek 2016년 8월 23일
a = datestr(now,31)
a=datestr(a,'yymmdd_HHMMSS')

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by