0

I am trying to read a text file that has textual data and separated by delimiter say 'abc' as consecutive characters separating the string that I want to read.

Ex: say text.txt file, as follows:

John abc Mike abc Micheal

Sandra abc Sarah abc David

I tried the following code but it did not work because delimiter is NOT a single character:

user = textscan(fid, '%s%s%s','Delimiter','abc');

Any help is highly appreciated

Zahran
  • 419
  • 4
  • 10

2 Answers2

1

Use a regular expression:

user = regexp(str, 'abc', 'split')

where str is a (cell)string read with something like:

str = textscan(fid, '%s','Delimiter','\n')
Rody Oldenhuis
  • 37,726
  • 7
  • 50
  • 96
0

I think this should do the trick:

user = textscan(fid, '%s%s%s', 'delimiter', {'abc'});
Marcin
  • 215,873
  • 14
  • 235
  • 294