Hi!
I am reading a file called “Symbola605.txt” with loadStrings().
Then I use .indexOf at each line in order to find a word that marks the beginning of a character list.
But it seems that .indexOf does not work with unicode files, even when combined with normalize(). Neither do includes() or match().
You can see the code with the attached file here:
I will copy here the code – but remember, to see it working you have to click the url above, since this sketch needs a file.
// I'm trying to read the file "symbola605" from the line containing a word.
// but it seems indexOf does not work,
// and neither does indexof + normalize().
//
var SymbolaChars,body;
function preload() {
SymbolaChars = loadStrings('Symbola605.txt', getSymbolaGroup);
}
// Finds the string "Symbola" inside the string
function getSymbolaGroup(){
var needle="Symbola".toLowerCase().normalize();
var out="";
var S="";
for(f=0;f<40;f++){
S=SymbolaChars[f].toLowerCase().normalize();
out+="["+int(f)+"] "+S;
out+="<br/>"
n=S.indexOf(needle);
if (n<0) {
out+="does not include '"+needle+"'";
} else {
out+="includes '"+needle+"' at "+n;
}
out+="<br/>";
}
createP(out);
}
Returns:
…
[22] symbola.ttf
does not include ‘symbola’
…
[26] symbola is not a merchandise.
does not include ‘symbola’
…
[30] symbola covers the following scripts and symbols supported by unicode:
does not include ‘symbola’
…
[38] character repertoire of symbola
does not include ‘symbola’
…
(and so on)