Aufgrund einer Wartung wird GitLab am 29.10. zwischen 9:00 und 10:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 29.10. between 9:00 and 10:00 am.

ita_string_cleanup.m 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
function outstr = ita_string_cleanup(instr)
%ITA_STRING_CLEANUP - Get rid off strange charaters
%  This function converts a string a leaving out all control characters and
%  Umlaut, etc. Only numbers and a..z and A..Z will remain;
%
%  Syntax:
%   str = ita_string_cleanup(str)

% <ITA-Toolbox>
% This file is part of the ITA-Toolbox. Some rights reserved. 
% You can find the license for this m-file in the license.txt file in the ITA-Toolbox folder. 
% </ITA-Toolbox>


% Author: Pascal Dietrich -- Email: pdi@akustik.rwth-aachen.de
% Created:  20-Feb-2011 




%% convert str
limit1 = double('az');
limit2 = double('AZ');

%% search for some characters to replace

instr = strrep(instr,'ß','ss');

instr = ita_string_replace(instr,[192,198],'A');
instr = ita_string_replace(instr,[199],'C');
instr = ita_string_replace(instr,[200 203],'E');
instr = ita_string_replace(instr,[204 207],'I');
instr = ita_string_replace(instr,[210 216],'O');
instr = ita_string_replace(instr,[217 220],'U');
instr = ita_string_replace(instr,[221],'Y');

instr = ita_string_replace(instr,[224 230],'a');
instr = ita_string_replace(instr,231,'c');
instr = ita_string_replace(instr,[232 235],'e');
instr = ita_string_replace(instr,[236 239],'i');
instr = ita_string_replace(instr,[242 248],'o');
instr = ita_string_replace(instr,[249 252],'u');
instr = ita_string_replace(instr,[253 255],'y');


%% only get the nice characters
% convert to number
instrNum = double(instr);

% only take numbers
idxNum = isstrprop(instr,'digit');

% only nice characters
idxChar1 = instrNum >= limit1(1) & instrNum <= limit1(end);
idxChar2 = instrNum >= limit2(1) & instrNum <= limit2(end);


% together
idx = idxNum | idxChar1 | idxChar2;

outstr = instr(idx);

end

function instr = ita_string_replace(instr,limits,character)
instrNum = double(instr);

% only characters between limits
idxChar = (instrNum >= limits(1)) & (instrNum <= limits(end));

instr(idxChar) = character;

end