What is the square symbol in text?

96 visualizzazioni (ultimi 30 giorni)
Norris
Norris il 19 Dic 2014
Risposto: Norris il 19 Dic 2014
Hi,
I am trying to read in a text file (of non-uniform format) and trying to extract a specific set of words.
When I have matlab print out the variables in the command window, I see the words are delimited by some character but I dont know what that is.
The delimiter looks like a square box and I tried searching and could not find what it is.
Does anyone know this is? and/or how to use it as a delimiting character? The word I am interested in is 'Arpeggiated'
I have attached my .txt file and the code is below. The text should show up in the command window.
Edit - I thought by saving the string to a new .txt file, I would be able to see the delimiter. This did not work either. There is no longer any space or delimiter between my words.
% input file
infile = '/Volumes/data/downloads/ARP Bells.txt';
% open file using fscanf
fid = fopen(infile,'r');
txt = fscanf(fid,'%s');
fclose(fid);
% first filter based on a specific string
ind = strfind(txt,'Aiyn'); % get index location
txt = txt(ind:end);
% second filter based on specific delimiter
tok = strtok(txt,'%');
% what is the square delimiter symbol?
tok = tok(230:end)
% save to see the symbol but doest show up in output
outfile = strrep(infile,'.smpr','_fixed.txt');
dlmwrite(outfile,tok,'delimiter','');

Risposta accettata

Geoff Hayes
Geoff Hayes il 19 Dic 2014
Norris - try converting the text string (from the original file with the squares) to an array of 8-bit unsigned integers so that you can see the ASCII code for that square (the code may be 254). Something like
uint8(txt)
Once you figure out the code for it, you can convert this integer value back to a string and use that as your delimiter.
  1 Commento
Norris
Norris il 19 Dic 2014
YES!! thanks so much. this was such a good tip. I used this with the suggestion below (per isakson) and found the symbol was char(29)
Used that to find and could extract my string.

Accedi per commentare.

Più risposte (2)

David Sanchez
David Sanchez il 19 Dic 2014
I took a look at your "ARP Bells.txt" file. Why do you look for Aiyn string?
ind = strfind(txt,'Aiyn'); % get index location
txt = txt(ind:end);
there's any Aiyn in your txt, the lines above makes txt an empty string.
Besides, that square symbol is the representation of your system of an alien character (unusual symbol and letter in a language not supported by your system).
If you are interested in Arpeggiated, why don't you just look for it:
% first filter based on a specific string
ind = strfind(txt,'Arpeggiated'); % get index location
txt = txt(ind:end)
  1 Commento
Norris
Norris il 19 Dic 2014
The file is one of thousands of files that I have.
The string Aiyn represents the maker of the file (it dynamically changes) and so I used that as the first filter search.
The word Arpeggiated is only one of dozens of attributes that I need to look for.

Accedi per commentare.


Norris
Norris il 19 Dic 2014
Thanks everyone for your suggestions. Here is the final code incase anyone else needs to do something similar.
% input file
infile = '/Volumes/data/downloads/ARP Bells.smpr';
% open file using fscanf
fid = fopen(infile,'r');
txt = fscanf(fid,'%s');
fclose(fid);
% first filter based on a specific string
ind = strfind(txt,'Aiyn'); % get index location
txt = txt(ind:end);
% second filter based on specific delimiter
tok = strtok(txt,'%');
% what is the square delimiter symbol?
tok = tok(235:end)
% convert to unit8
uint8(tok)
% find the index location of symbol and count the columns
% symbol = 29
ind3 = strfind(tok,char(29))
% extract word
tok(ind3+1:end)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by