Why am I unable to preserve upper case letters using REGEXPREP in MATLAB 7.4 (R2007a)?

1 view (last 30 days)
I want to replace parameters in my ascii file using REGEXPREP associated with its option "preservecase".
In command line I realize:
script('filtering_P.script',{'<TSInput1_File_Name>';'<Filter_Type>';'<Frequency1>';'<Frequency2>'},{'d:\Test.RSP';'UPPERCASE';'10';'20'})
My "script" function is:
function script(file,otext,ntext)
%script: replace parameter in a script file
%
% Edit_Script : This function finds and replaces parameter in a script file
%
% file: text file name (with or without path)
% otext: text to be replaced (old text)
% ntext: replacing text (new text)
%
%
ntext_nonprinting=regexprep(ntext,'\','\\\\\\\', 'preservecase');
ntext=ntext_nonprinting;
% Obtaining the file full path
[fpath,fname,fext] = fileparts(file);
if isempty(fpath)
out_path = pwd;
elseif fpath(1)=='.'
out_path = [pwd filesep fpath];
else
out_path = fpath;
end
% Reading the file contents
k=1;
fid = fopen([out_path filesep fname fext],'r');
while 1
line{k} = fgetl(fid);
if ~ischar(line{k})
break;
end
k=k+1;
end
fclose(fid);
%Number of lines
nlines = length(line)-1;
change_counter=0;
for i=1:nlines
if ~isempty(regexp(line{i},otext))
line{i} = regexprep(line{i},otext,ntext, 'preservecase');
change_counter = change_counter + 1;
end
end
if change_counter~=0
% Writing to file
fid2 = fopen([out_path filesep fname fext],'w');
for i=1:nlines
fprintf(fid2,[line{i} '\n']);
end
fclose(fid2);
end
In my ascii file I don't obtain the expected result:
SetProperty(FastFourierFilter1,Type,UPPERCASE)
but
SetProperty(FastFourierFilter1,Type,Uppercase)
Upper Case letters are not preserved.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
Upper case letters can be preserved using the option "matchcase" of REGEXPREP in MATLAB 7.4 (R2007a).

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products


Release

R2007a

Community Treasure Hunt

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

Start Hunting!