Strings

Replace substring


% replace all characters "a" with "x"
strrep("a1 a2 a3 a4", "a", "x")
   "x1 x2 x3 x4"

% replace file ending ".txt" with ".csv"
filename    = "mydata.txt"
newFilename = strrep(filename, ".txt", ".csv")
  mydata.csv

% remove file ending ".txt"
filename = "mydata.txt"
rawname  = strrep(filename, ".txt", "")
  mydata

% alternatively, use: "erase"
rawname = erase(filename,".txt")
  mydata


Check / find substring


check for substring

~isempty(strfind("Friday","day"))
 1  % True: substring "day" appears in string "Friday"

get position of substring
strfind("Friday","day")
 4  % substring "day" appears at character position 4 in string "Friday"





Subpages (3): Frequencies Join remove