Replace a specific portion of a string

조회 수: 4 (최근 30일)
Zoe Zhang
Zoe Zhang 2011년 8월 24일
I have a cell array of strings,
'SPY US 09/17/11 P118 Equity'
'XOM US 08/20/11 P72.5 Equity'
'AAPL US 12/17/11 P375 Equity'
....
I would like to keep the left side and the right side but replace the dates all into say 01/01/11. So the output could be:
'SPY US 01/01/11 P118 Equity'
'XOM US 01/01/11 P72.5 Equity'
'AAPL US 01/01/11 P375 Equity'
....
Anyone know a quick way? Thanks in advance!

채택된 답변

Oleg Komarov
Oleg Komarov 2011년 8월 24일
cs = {'SPY US 09/17/11 P118 Equity'
'XOM US 08/20/11 P72.5 Equity'
'AAPL US 12/17/11 P375 Equity'};
regexprep(cs, '\d{2}/\d{2}/\d{2}','01/01/11')
  댓글 수: 1
Zoe Zhang
Zoe Zhang 2011년 8월 24일
Aha, exactly I wanted (as I said below...) Thanks so much~~

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

추가 답변 (1개)

Zoe Zhang
Zoe Zhang 2011년 8월 24일
>> ticker = 'SPY US 09/17/11 P118 Equity'; >> position = findstr('/',ticker)
position =
10 13
>> ticker(position(1)-2:position(2)+2) = '01/01/11'
ticker =
SPY US 01/01/11 P118 Equity
There should be a easier way right? Some thing like modifiedStr = strrep('SPY US 09/17/11 P118 Equity', '$$/$$/$$','01/01/01')

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by