newstring = strrep(orgstring, word1,word2)
strrep 함수는 orgstring에서 word1을 찾아서 word2로 바꾸어 newstring에 저장한다.
예제)
str1 = 'lonesome';
str2 = strrep(str1,'lone', 'awe');
결과 str2 = 'awesome'
STRREP Replace string with another.
MODIFIEDSTR = STRREP(ORIGSTR,OLDSUBSTR,NEWSUBSTR) replaces all
occurrences of the string OLDSUBSTR within string ORIGSTR with the
string NEWSUBSTR.
Notes:
* STRREP accepts input combinations of single strings, strings in
scalar cells, and same-sized cell arrays of strings. If any inputs
are cell arrays, STRREP returns a cell array.
* STRREP does not find empty strings for replacement. That is, when
ORIGSTR and OLDSUBSTR both contain the empty string (''), STRREP does
not replace '' with the contents of NEWSUBSTR.
Examples:
% Example 1: Replace text in a character array.
claim = 'This is a good example';
new_claim = strrep(claim, 'good', 'great')
new_claim =
This is a great example.
% Example 2: Replace text in a cell array.
c_files = {'c:\cookies.m'; ...
'c:\candy.m'; ...
'c:\calories.m'};
d_files = strrep(c_files, 'c:', 'd:')
d_files =
'd:\cookies.m'
'd:\candy.m'
'd:\calories.m'
% Example 3: Replace text in a cell array with values in a second cell
% array.
missing_info = {'Start: __'; ...
'End: __'};
dates = {'01/01/2001'; ...
'12/12/2002'};
complete = strrep(missing_info, '__', dates)
complete =
'Start: 01/01/2001'
'End: 12/12/2002'
See also strfind, regexprep.
Reference page in Help browser
doc strrep
'연구관련 > 프로그래밍' 카테고리의 다른 글
파일 리스트 txt파일로 저장 (0) | 2012.11.30 |
---|---|
[MATLAB] textscan 파일에 쓰여진 문자열 읽기 (0) | 2012.11.30 |
OpenCV IplImage 색상 (픽셀값) 초기화 (0) | 2012.05.30 |
[ Matlab ] Image Data Scaling (0) | 2011.12.23 |
xp 32bit에서 메모리 2G 이상 할당 받기 (0) | 2011.10.18 |