MATLAB: Add bits before last alphabet of every word

laststringword

How to add watermarks bit before the last alphabet of every word of a string.

Best Answer

Try this:
str = 'MATLAB is a super awesome program';
words = strsplit(str)
for k = 1 : length(words)
thisString = words{k};
if length(thisString) >= 2
words{k} = sprintf('%s%c%c', thisString(1:end-1), char(hex2dec('2020D')), thisString(end));
end
end
% Reconstruct into a single string
words
str2 = [];
for k = 1 : length(words)
thisString = words{k};
str2 = sprintf('%s %s', str2, thisString);
end
str2
You'll see in the command window:
words =
1×6 cell array
{'MATLAB'} {'is'} {'a'} {'super'} {'awesome'} {'program'}
words =
1×6 cell array
{'MATLAB'} {'is'} {'a'} {'super'} {'awesome'} {'program'}
str2 =
' MATLAB is a super awesome program'
except that the FFFF in the boxes don't show up in MATLAB - they're just little empty boxes.