replace every " with an ' in an cell array in matlab

You can use strrep() function to achieve this. Here is an example:

main.m
% create a cell array containing strings
strs = {'John "Doe"', 'Jane "Doe"', 'Johnny "Appleseed"'};

% use strrep() to replace all double quotes with single quotes
strs = strrep(strs, '"', '''');

% display the modified cell array
disp(strs);
243 chars
9 lines

Output:

main.m
'John ''Doe'''
'Jane ''Doe'''
'Johnny ''Appleseed'''
53 chars
4 lines

In this code, strrep() replaces all occurrences of " with ' in the cell array strs. The resulting cell array is displayed using disp().

related categories

gistlibby LogSnag